MCPcopy Create free account
hub / github.com/Simsys/qhexedit2 / getChunkIndex

Method getChunkIndex

src/chunks.cpp:276–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276int Chunks::getChunkIndex(qint64 absPos)
277{
278 // This routine checks, if there is already a copied chunk available. If os, it
279 // returns a reference to it. If there is no copied chunk available, original
280 // data will be copied into a new chunk.
281
282 int foundIdx = -1;
283 int insertIdx = 0;
284 qint64 ioDelta = 0;
285
286
287 for (int idx=0; idx < _chunks.size(); idx++)
288 {
289 Chunk chunk = _chunks[idx];
290 if ((absPos >= chunk.absPos) && (absPos < (chunk.absPos + chunk.data.size())))
291 {
292 foundIdx = idx;
293 break;
294 }
295 if (absPos < chunk.absPos)
296 {
297 insertIdx = idx;
298 break;
299 }
300 ioDelta += chunk.data.size() - CHUNK_SIZE;
301 insertIdx = idx + 1;
302 }
303
304 if (foundIdx == -1)
305 {
306 Chunk newChunk;
307 qint64 readAbsPos = absPos - ioDelta;
308 qint64 readPos = (readAbsPos & READ_CHUNK_MASK);
309 _ioDevice->open(QIODevice::ReadOnly);
310 _ioDevice->seek(readPos);
311 newChunk.data = _ioDevice->read(CHUNK_SIZE);
312 _ioDevice->close();
313 newChunk.absPos = absPos - (readAbsPos - readPos);
314 newChunk.dataChanged = QByteArray(newChunk.data.size(), char(0));
315 _chunks.insert(insertIdx, newChunk);
316 foundIdx = insertIdx;
317 }
318 return foundIdx;
319}
320
321
322#ifdef MODUL_TEST

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.80
openMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected