llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (serge-sans-paille)

<details>
<summary>Changes</summary>

…ierLocBuilder

This avoids a deepcopy of the manually managed underlying Buffer.

This is a follow-up to #<!-- -->180482.

---
Full diff: https://github.com/llvm/llvm-project/pull/180484.diff


2 Files Affected:

- (modified) clang/include/clang/AST/NestedNameSpecifierBase.h (+4) 
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (+26) 


``````````diff
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);

``````````

</details>


https://github.com/llvm/llvm-project/pull/180484
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to