diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-09-15 17:58:03 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-09-15 17:58:03 +0000 |
commit | 41e574e2fd706252b8b2931b522261f5bbdc74b3 (patch) | |
tree | 440e6e59fec6945fc13bbac2c38cf1b1f1146998 /lib/Rewrite | |
parent | c447b36b00dc6d193adc89e7f905c221822de437 (diff) | |
download | clang-41e574e2fd706252b8b2931b522261f5bbdc74b3.tar.gz |
Use intrusive refcounted pointers to manage RopeRefCountString lifetime.
std::shared_ptr<char []> would be even nicer, but shared_ptr doesn't work
with arrays :(
No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite')
-rw-r--r-- | lib/Rewrite/RewriteRope.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/Rewrite/RewriteRope.cpp b/lib/Rewrite/RewriteRope.cpp index ef8abfcadc..1c82ee4a67 100644 --- a/lib/Rewrite/RewriteRope.cpp +++ b/lib/Rewrite/RewriteRope.cpp @@ -788,18 +788,14 @@ RopePiece RewriteRope::MakeRopeString(const char *Start, const char *End) { // Otherwise, this was a small request but we just don't have space for it // Make a new chunk and share it with later allocations. - if (AllocBuffer) - AllocBuffer->dropRef(); - unsigned AllocSize = offsetof(RopeRefCountString, Data) + AllocChunkSize; - AllocBuffer = reinterpret_cast<RopeRefCountString *>(new char[AllocSize]); - AllocBuffer->RefCount = 0; - memcpy(AllocBuffer->Data, Start, Len); + RopeRefCountString *Res = + reinterpret_cast<RopeRefCountString *>(new char[AllocSize]); + Res->RefCount = 0; + memcpy(Res->Data, Start, Len); + AllocBuffer = Res; AllocOffs = Len; - // Start out the new allocation with a refcount of 1, since we have an - // internal reference to it. - AllocBuffer->addRef(); return RopePiece(AllocBuffer, 0, Len); } |