[PATCH] D115382: ADT: Avoid using SmallVector::set_size() in SmallString
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 11 17:38:19 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
dexonsmith marked 2 inline comments as done.
Closed by commit rG4d04526bf48d: ADT: Avoid using SmallVector::set_size() in SmallString (authored by dexonsmith).
Changed prior to commit:
https://reviews.llvm.org/D115382?vs=392891&id=399144#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115382/new/
https://reviews.llvm.org/D115382
Files:
llvm/include/llvm/ADT/SmallString.h
Index: llvm/include/llvm/ADT/SmallString.h
===================================================================
--- llvm/include/llvm/ADT/SmallString.h
+++ llvm/include/llvm/ADT/SmallString.h
@@ -70,16 +70,16 @@
/// Append from a list of StringRefs.
void append(std::initializer_list<StringRef> Refs) {
- size_t SizeNeeded = this->size();
+ size_t CurrentSize = this->size();
+ size_t SizeNeeded = CurrentSize;
for (const StringRef &Ref : Refs)
SizeNeeded += Ref.size();
- this->reserve(SizeNeeded);
- auto CurEnd = this->end();
+ this->resize_for_overwrite(SizeNeeded);
for (const StringRef &Ref : Refs) {
- this->uninitialized_copy(Ref.begin(), Ref.end(), CurEnd);
- CurEnd += Ref.size();
+ std::copy(Ref.begin(), Ref.end(), this->begin() + CurrentSize);
+ CurrentSize += Ref.size();
}
- this->set_size(SizeNeeded);
+ assert(CurrentSize == this->size());
}
/// @}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115382.399144.patch
Type: text/x-patch
Size: 947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220112/370ec395/attachment.bin>
More information about the llvm-commits
mailing list