From ca305a0bbbf6a33a010c7e89f0c7a5a23a1bcf43 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 8 Nov 2007 17:59:48 +0000 Subject: [PATCH] Simplify interface to MakeRopeString. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43895 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Rewrite/RewriteRope.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/include/clang/Rewrite/RewriteRope.h b/include/clang/Rewrite/RewriteRope.h index 7d4863c293..3d5b023781 100644 --- a/include/clang/Rewrite/RewriteRope.h +++ b/include/clang/Rewrite/RewriteRope.h @@ -32,7 +32,11 @@ struct RopePiece { RopePiece(RopeRefCountString *Str, unsigned Start, unsigned End) : StrData(Str), StartOffs(Start), EndOffs(End) { - StrData->RefCount++; + ++StrData->RefCount; + } + RopePiece(const RopePiece &RP) + : StrData(RP.StrData), StartOffs(RP.StartOffs), EndOffs(RP.EndOffs) { + ++StrData->RefCount; } ~RopePiece() { @@ -162,8 +166,7 @@ public: void assign(const char *Start, const char *End) { clear(); - Chunks.push_back(new RopePiece(MakeRopeString(Start, End), 0, - End-Start)); + Chunks.push_back(new RopePiece(MakeRopeString(Start, End))); CurSize = End-Start; } @@ -172,8 +175,8 @@ public: unsigned ChunkNo = SplitAt(Loc); - RopeRefCountString *Str = MakeRopeString(Start, End); - Chunks.insert(Chunks.begin()+ChunkNo, new RopePiece(Str, 0, End-Start)); + Chunks.insert(Chunks.begin()+ChunkNo, + new RopePiece(MakeRopeString(Start, End))); CurSize += End-Start; } @@ -253,13 +256,13 @@ public: } private: - RopeRefCountString *MakeRopeString(const char *Start, const char *End) { + RopePiece MakeRopeString(const char *Start, const char *End) { unsigned Size = End-Start+sizeof(RopeRefCountString)-1; RopeRefCountString *Res = reinterpret_cast(new char[Size]); Res->RefCount = 0; memcpy(Res->Data, Start, End-Start); - return Res; + return RopePiece(Res, 0, End-Start); } unsigned getChunkIdx(iterator Loc) const { -- 2.40.0