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

Method removeItem

kdevplatform/language/duchain/codemodel.cpp:290–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290void CodeModel::removeItem(const IndexedString& file, const IndexedQualifiedIdentifier& id)
291{
292 if (!id.isValid())
293 return;
294
295 ifDebug(qCDebug(LANGUAGE) << "removeItem" << file.str() << id.identifier().toString(); )
296 CodeModelRepositoryItem item;
297 item.file = file;
298 CodeModelRequestItem request(item);
299
300 LockedItemRepository::write<CodeModel>([&](CodeModelRepo& repo) {
301 uint index = repo.findIndex(item);
302
303 if (index) {
304 CodeModelItem searchItem;
305 searchItem.id = id;
306
307 DynamicItem<CodeModelRepositoryItem, true> oldItem = repo.dynamicItemFromIndex(index);
308
309 EmbeddedTreeAlgorithms<CodeModelItem, CodeModelItemHandler> alg(oldItem->items(), oldItem->itemsSize(),
310 oldItem->centralFreeItem);
311
312 int listIndex = alg.indexOf(searchItem);
313 if (listIndex == -1)
314 return;
315
316 auto* items = const_cast<CodeModelItem*>(oldItem->items());
317
318 --items[listIndex].referenceCount;
319
320 if (oldItem->items()[listIndex].referenceCount)
321 return; // Nothing to remove, there's still a reference-count left
322
323 // We have reduced the reference-count to zero, so remove the item from the list
324
325 EmbeddedTreeRemoveItem<CodeModelItem, CodeModelItemHandler> remove(items, oldItem->itemsSize(),
326 oldItem->centralFreeItem, searchItem);
327
328 uint newItemCount = remove.newItemCount();
329 if (newItemCount != oldItem->itemsSize()) {
330 if (newItemCount == 0) {
331 // Has become empty, delete the item
332 repo.deleteItem(index);
333
334 return;
335 } else {
336 // Make smaller
337 item.itemsList().resize(newItemCount);
338 remove.transferData(item.itemsList().data(), item.itemsSize(), &item.centralFreeItem);
339
340 // Delete the old list
341 repo.deleteItem(index);
342 // Add the new list
343 repo.index(request);
344 return;
345 }
346 }
347 }

Callers 9

setInSymbolTableMethod · 0.80
removeBuildConfigMethod · 0.80
removeConfigMethod · 0.80
removeBuildDirMethod · 0.80
setSearchLocationsMethod · 0.80
renewModelMethod · 0.80
refreshMethod · 0.80
clearSearchHistoryMethod · 0.80
removeBuildDirMethod · 0.80

Calls 13

strMethod · 0.80
dynamicItemFromIndexMethod · 0.80
isValidMethod · 0.45
toStringMethod · 0.45
identifierMethod · 0.45
findIndexMethod · 0.45
itemsMethod · 0.45
indexOfMethod · 0.45
newItemCountMethod · 0.45
deleteItemMethod · 0.45
transferDataMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected