Author: serge-sans-paille Date: 2026-02-25T17:29:18Z New Revision: 1b1840dd13cd89f9816e264e9ae0379d32e15078
URL: https://github.com/llvm/llvm-project/commit/1b1840dd13cd89f9816e264e9ae0379d32e15078 DIFF: https://github.com/llvm/llvm-project/commit/1b1840dd13cd89f9816e264e9ae0379d32e15078.diff LOG: [clang] [NFC] Improve move-assign and move-constructor for NestedNameSpecifierLocBuilder (#180484) This avoids a deep copy of the manually managed underlying Buffer. This is a follow-up to #180482. Added: Modified: clang/include/clang/AST/NestedNameSpecifierBase.h clang/lib/AST/NestedNameSpecifier.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h index 8f4bbe97f6e9a..3330fed58ba79 100644 --- a/clang/include/clang/AST/NestedNameSpecifierBase.h +++ b/clang/include/clang/AST/NestedNameSpecifierBase.h @@ -450,10 +450,14 @@ class NestedNameSpecifierLocBuilder { public: NestedNameSpecifierLocBuilder() = default; NestedNameSpecifierLocBuilder(const NestedNameSpecifierLocBuilder &Other); + NestedNameSpecifierLocBuilder(NestedNameSpecifierLocBuilder &&Other); NestedNameSpecifierLocBuilder & operator=(const NestedNameSpecifierLocBuilder &Other); + NestedNameSpecifierLocBuilder & + operator=(NestedNameSpecifierLocBuilder &&Other); + ~NestedNameSpecifierLocBuilder() { if (BufferCapacity) free(Buffer); diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp index c6af91f5c0083..c217e5dfa98b2 100644 --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -208,6 +208,13 @@ NestedNameSpecifierLocBuilder(const NestedNameSpecifierLocBuilder &Other) BufferCapacity); } +NestedNameSpecifierLocBuilder::NestedNameSpecifierLocBuilder( + NestedNameSpecifierLocBuilder &&Other) + : Representation(std::move(Other.Representation)), + Buffer(std::exchange(Other.Buffer, nullptr)), + BufferSize(std::exchange(Other.BufferSize, 0)), + BufferCapacity(std::exchange(Other.BufferCapacity, 0)) {} + NestedNameSpecifierLocBuilder & NestedNameSpecifierLocBuilder:: operator=(const NestedNameSpecifierLocBuilder &Other) { @@ -247,6 +254,21 @@ operator=(const NestedNameSpecifierLocBuilder &Other) { return *this; } +NestedNameSpecifierLocBuilder &NestedNameSpecifierLocBuilder::operator=( + NestedNameSpecifierLocBuilder &&Other) { + Representation = std::move(Other.Representation); + + // Free our storage, if we have any. + if (BufferCapacity) { + free(Buffer); + } + Buffer = std::exchange(Other.Buffer, nullptr); + BufferSize = std::exchange(Other.BufferSize, 0); + BufferCapacity = std::exchange(Other.BufferCapacity, 0); + + return *this; +} + void NestedNameSpecifierLocBuilder::Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc) { assert(!Representation); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
