[PATCH] D132512: [SmallVector] Reallocate if assigned memory is right after the current vector, created with capacity 0
Alina Sbirlea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 30 10:52:27 PDT 2022
asbirlea added a comment.
In D132512#3758117 <https://reviews.llvm.org/D132512#3758117>, @fhahn wrote:
> Can this be limited to instantiations where the original original size is 0, as IIUC this only applies to `llvm::SmallVector<T, 0>`?
I don't know how to properly check for that.
Say the original instantiation is `llvm::SmallVector<T, 0>`, so initially capacity is set to 0, but after the vector is used, the size and capacity have increased, and the heap allocated memory is in a completely different region (safe). Now say that we're at a point where we want to further increase capacity, and it just so happens that the memory right after (at FirstEl) is available and, this time, *that's* what `safe_realloc` returns. This is the case at line:153.
The case at line :145, we're already in a case where the vector has no heap allocated since BeginX == FirstEl (if we entered this condition and there's heap allocated, we failed to fix the problem this patch is trying to fix...). So the only scenario in which `NewElts` can be equal to `FirstEl` is when the vector was created with capacity 0. The check would be redundant here.
The third case, when `mallocForGrow` is called (line :132), it's also possible the capacity was already increased and this is called to increase it further. So checking for capacity 0 here wouldn't stop allocating right at FirstEl.
Please let me know if I missed something in the above reasoning.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132512/new/
https://reviews.llvm.org/D132512
More information about the llvm-commits
mailing list