r213178 - Simplify memory management in NestedNameSpecifierLocBuilder.

Serge Pavlov sepavloff at gmail.com
Wed Jul 16 11:18:16 PDT 2014


Author: sepavloff
Date: Wed Jul 16 13:18:13 2014
New Revision: 213178

URL: http://llvm.org/viewvc/llvm-project?rev=213178&view=rev
Log:
Simplify memory management in NestedNameSpecifierLocBuilder.

With this change the memory of buffer in NestedNameSpecifierLocBuilder
is allocated in one place. It also prevents from allocation of tiny blocks.

Modified:
    cfe/trunk/lib/AST/NestedNameSpecifier.cpp

Modified: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NestedNameSpecifier.cpp?rev=213178&r1=213177&r2=213178&view=diff
==============================================================================
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp (original)
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp Wed Jul 16 13:18:13 2014
@@ -453,10 +453,8 @@ NestedNameSpecifierLocBuilder(const Nest
   }
   
   // Deep copy
-  BufferSize = Other.BufferSize;
-  BufferCapacity = Other.BufferSize;
-  Buffer = static_cast<char *>(malloc(BufferCapacity));
-  memcpy(Buffer, Other.Buffer, BufferSize);
+  Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
+         BufferCapacity);
 }
 
 NestedNameSpecifierLocBuilder &
@@ -492,10 +490,8 @@ operator=(const NestedNameSpecifierLocBu
   }
   
   // Deep copy.
-  BufferSize = Other.BufferSize;
-  BufferCapacity = BufferSize;
-  Buffer = static_cast<char *>(malloc(BufferSize));
-  memcpy(Buffer, Other.Buffer, BufferSize);
+  Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
+         BufferCapacity);
   return *this;
 }
 





More information about the cfe-commits mailing list