[sancov] Avoid unnecessary unique_ptr

llvm-svn: 364175
This commit is contained in:
Fangrui Song 2019-06-24 10:23:47 +00:00
parent b502a44110
commit 078d711908
1 changed files with 10 additions and 12 deletions

View File

@ -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> object() { return make_unique<Object>(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> array() { return make_unique<Array>(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<std::string> WrittenIds;
ByFn->key(FunctionName);
ByFn.key(FunctionName);
// Output <point_id> : "<line>:<col>".
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;
}
}