MCPcopy Create free account
hub / github.com/KDE/kdevelop / initializeBucket

Method initializeBucket

kdevplatform/serialization/itemrepository.h:2301–2357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2299 }
2300
2301 inline MyBucket* initializeBucket(int bucketNumber) const
2302 {
2303 using namespace ItemRepositoryUtils;
2304
2305 Q_ASSERT(bucketNumber);
2306#ifdef DEBUG_MONSTERBUCKETS
2307 // ensure that the previous N buckets are no monster buckets that overlap the requested bucket
2308 for (int offset = 1; offset < 5; ++offset) {
2309 int test = bucketNumber - offset;
2310 if (test >= 0 && m_buckets[test]) {
2311 Q_ASSERT(m_buckets[test]->monsterBucketExtent() < offset);
2312 }
2313 }
2314
2315#endif
2316
2317 auto& bucket = m_buckets[bucketNumber];
2318 if (!bucket) {
2319 bucket = new MyBucket();
2320
2321 bool doMMapLoading = ( bool )m_fileMap;
2322
2323 uint offset = ((bucketNumber - 1) * MyBucket::DataSize);
2324 if (m_file && offset < m_fileMapSize && doMMapLoading &&
2325 *reinterpret_cast<uint*>(m_fileMap + offset) == 0) {
2326// qDebug() << "loading bucket mmap:" << bucketNumber;
2327 bucket->initializeFromMap(reinterpret_cast<char*>(m_fileMap + offset));
2328 } else if (m_file) {
2329 //Either memory-mapping is disabled, or the item is not in the existing memory-map,
2330 //so we have to load it the classical way.
2331 bool res = m_file->open(QFile::ReadOnly);
2332
2333 if (offset + BucketStartOffset < m_file->size()) {
2334 VERIFY(res);
2335 offset += BucketStartOffset;
2336 m_file->seek(offset);
2337 int monsterBucketExtent;
2338 readValue(m_file, &monsterBucketExtent);
2339 m_file->seek(offset);
2340 ///FIXME: use the data here instead of copying it again in prepareChange
2341 QByteArray data = m_file->read((1 + monsterBucketExtent) * MyBucket::DataSize);
2342 bucket->initializeFromMap(data.data());
2343 bucket->prepareChange();
2344 } else {
2345 bucket->initialize(0);
2346 }
2347
2348 m_file->close();
2349 } else {
2350 bucket->initialize(0);
2351 }
2352 } else {
2353 bucket->initialize(0);
2354 }
2355
2356 return bucket;
2357 }
2358

Callers

nothing calls this directly

Calls 10

readValueFunction · 0.85
monsterBucketExtentMethod · 0.80
initializeFromMapMethod · 0.80
prepareChangeMethod · 0.80
openMethod · 0.45
sizeMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
initializeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected