From 24fcfec608cf05670a931351b5e4714dab0d916a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 24 Jun 2019 10:23:47 +0000 Subject: [PATCH] [sancov] Avoid unnecessary unique_ptr git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364175 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/sancov/sancov.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/sancov/sancov.cpp b/tools/sancov/sancov.cpp index a385890aaac..dd2b2dd7470 100644 --- a/tools/sancov/sancov.cpp +++ b/tools/sancov/sancov.cpp @@ -297,7 +297,6 @@ public: OS << "{"; W->Indent++; } - Object(const Object &) = delete; ~Object() { W->Indent--; OS << "\n"; @@ -321,13 +320,12 @@ public: int Index = -1; }; - std::unique_ptr object() { return make_unique(this, OS); } + Object object() { return {this, OS}; } // Helper RAII class to output JSON arrays. class Array { public: Array(raw_ostream &OS) : OS(OS) { OS << "["; } - Array(const Array &) = delete; ~Array() { OS << "]"; } void next() { Index++; @@ -340,7 +338,7 @@ public: int Index = -1; }; - std::unique_ptr array() { return make_unique(OS); } + Array array() { return {OS}; } private: void indent() { OS.indent(Indent * 2); } @@ -386,7 +384,7 @@ static void operator<<(JSONWriter &W, for (const auto &P : PointsByFile) { std::string FileName = P.first; - ByFile->key(FileName); + ByFile.key(FileName); // Group points by function. auto ByFn(W.object()); @@ -401,7 +399,7 @@ static void operator<<(JSONWriter &W, std::string FunctionName = P.first; std::set WrittenIds; - ByFn->key(FunctionName); + ByFn.key(FunctionName); // Output : ":". auto ById(W.object()); @@ -413,7 +411,7 @@ static void operator<<(JSONWriter &W, continue; WrittenIds.insert(Point->Id); - ById->key(Point->Id); + ById.key(Point->Id); W << (utostr(Loc.Line) + ":" + utostr(Loc.Column)); } } @@ -425,24 +423,24 @@ static void operator<<(JSONWriter &W, const SymbolizedCoverage &C) { auto O(W.object()); { - O->key("covered-points"); + O.key("covered-points"); auto PointsArray(W.array()); - for (const auto &P : C.CoveredIds) { - PointsArray->next(); + for (const std::string &P : C.CoveredIds) { + PointsArray.next(); W << P; } } { if (!C.BinaryHash.empty()) { - O->key("binary-hash"); + O.key("binary-hash"); W << C.BinaryHash; } } { - O->key("point-symbol-info"); + O.key("point-symbol-info"); W << C.Points; } } -- 2.40.0