https://github.com/serge-sans-paille created https://github.com/llvm/llvm-project/pull/180484
…ierLocBuilder This avoids a deepcopy of the manually managed underlying Buffer. This is a follow-up to #180482. >From 66129949425ef5816bb90a77b835e2795bcaa253 Mon Sep 17 00:00:00 2001 From: serge-sans-paille <[email protected]> Date: Mon, 9 Feb 2026 09:23:18 +0100 Subject: [PATCH] [clang] Improve move-assign and move-constructor for NestedNameSpecifierLocBuilder This avoids a deepcopy of the manually managed underlying Buffer. This is a follow-up to #180482. --- .../clang/AST/NestedNameSpecifierBase.h | 4 +++ clang/lib/AST/NestedNameSpecifier.cpp | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) 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..5668900e6733c 100644 --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -208,6 +208,14 @@ NestedNameSpecifierLocBuilder(const NestedNameSpecifierLocBuilder &Other) BufferCapacity); } +NestedNameSpecifierLocBuilder::NestedNameSpecifierLocBuilder( + NestedNameSpecifierLocBuilder &&Other) + : Representation(std::move(Other.Representation)), Buffer(Other.Buffer), + BufferSize(Other.BufferSize), BufferCapacity(Other.BufferCapacity) { + Other.buffer = nullptr; + Other.BufferCapacity = Other.size = 0; +} + NestedNameSpecifierLocBuilder & NestedNameSpecifierLocBuilder:: operator=(const NestedNameSpecifierLocBuilder &Other) { @@ -247,6 +255,24 @@ 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 = Other.Buffer; + BufferSize = Other.BufferSize; + BufferCapacity = Other.BufferCapacity; + + Other.Buffer = nullptr; + Other.BufferSize = 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
