1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[sancov] Avoid unnecessary unique_ptr

llvm-svn: 364175
This commit is contained in:
Fangrui Song 2019-06-24 10:23:47 +00:00
parent e7b30c99aa
commit 4c33942c6e

View File

@ -297,7 +297,6 @@ public:
OS << "{"; OS << "{";
W->Indent++; W->Indent++;
} }
Object(const Object &) = delete;
~Object() { ~Object() {
W->Indent--; W->Indent--;
OS << "\n"; OS << "\n";
@ -321,13 +320,12 @@ public:
int Index = -1; int Index = -1;
}; };
std::unique_ptr<Object> object() { return make_unique<Object>(this, OS); } Object object() { return {this, OS}; }
// Helper RAII class to output JSON arrays. // Helper RAII class to output JSON arrays.
class Array { class Array {
public: public:
Array(raw_ostream &OS) : OS(OS) { OS << "["; } Array(raw_ostream &OS) : OS(OS) { OS << "["; }
Array(const Array &) = delete;
~Array() { OS << "]"; } ~Array() { OS << "]"; }
void next() { void next() {
Index++; Index++;
@ -340,7 +338,7 @@ public:
int Index = -1; int Index = -1;
}; };
std::unique_ptr<Array> array() { return make_unique<Array>(OS); } Array array() { return {OS}; }
private: private:
void indent() { OS.indent(Indent * 2); } void indent() { OS.indent(Indent * 2); }
@ -386,7 +384,7 @@ static void operator<<(JSONWriter &W,
for (const auto &P : PointsByFile) { for (const auto &P : PointsByFile) {
std::string FileName = P.first; std::string FileName = P.first;
ByFile->key(FileName); ByFile.key(FileName);
// Group points by function. // Group points by function.
auto ByFn(W.object()); auto ByFn(W.object());
@ -401,7 +399,7 @@ static void operator<<(JSONWriter &W,
std::string FunctionName = P.first; std::string FunctionName = P.first;
std::set<std::string> WrittenIds; std::set<std::string> WrittenIds;
ByFn->key(FunctionName); ByFn.key(FunctionName);
// Output <point_id> : "<line>:<col>". // Output <point_id> : "<line>:<col>".
auto ById(W.object()); auto ById(W.object());
@ -413,7 +411,7 @@ static void operator<<(JSONWriter &W,
continue; continue;
WrittenIds.insert(Point->Id); WrittenIds.insert(Point->Id);
ById->key(Point->Id); ById.key(Point->Id);
W << (utostr(Loc.Line) + ":" + utostr(Loc.Column)); W << (utostr(Loc.Line) + ":" + utostr(Loc.Column));
} }
} }
@ -425,24 +423,24 @@ static void operator<<(JSONWriter &W, const SymbolizedCoverage &C) {
auto O(W.object()); auto O(W.object());
{ {
O->key("covered-points"); O.key("covered-points");
auto PointsArray(W.array()); auto PointsArray(W.array());
for (const auto &P : C.CoveredIds) { for (const std::string &P : C.CoveredIds) {
PointsArray->next(); PointsArray.next();
W << P; W << P;
} }
} }
{ {
if (!C.BinaryHash.empty()) { if (!C.BinaryHash.empty()) {
O->key("binary-hash"); O.key("binary-hash");
W << C.BinaryHash; W << C.BinaryHash;
} }
} }
{ {
O->key("point-symbol-info"); O.key("point-symbol-info");
W << C.Points; W << C.Points;
} }
} }