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 | fdacdb26afab4381db0f733d4fcc28b1ec0bcc95 (patch) | |
| tree | 9aa363a8c3e1aa2103793482156a52c44c69dc27 /clang/lib/Rewrite | |
| parent | f090bda1d57902818e003df916683b181718310d (diff) | |
| download | bcm5719-llvm-fdacdb26afab4381db0f733d4fcc28b1ec0bcc95.tar.gz bcm5719-llvm-fdacdb26afab4381db0f733d4fcc28b1ec0bcc95.zip | |
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.
llvm-svn: 217798
Diffstat (limited to 'clang/lib/Rewrite')
| -rw-r--r-- | clang/lib/Rewrite/RewriteRope.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/clang/lib/Rewrite/RewriteRope.cpp b/clang/lib/Rewrite/RewriteRope.cpp index ef8abfcadc0..1c82ee4a67e 100644 --- a/clang/lib/Rewrite/RewriteRope.cpp +++ b/clang/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); } |

