From a17c23426e7b2724639cd90c23759299cdaffbb7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Oct 2014 15:54:40 +0200 Subject: [PATCH] printValue(): Don't print for repeated values --- src/libexpr/eval.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 43d8f1399..46a425900 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -38,13 +38,13 @@ void Bindings::sort() } -static void printValue(std::ostream & str, std::set & seen, const Value & v) +static void printValue(std::ostream & str, std::set & active, const Value & v) { - if (seen.find(&v) != seen.end()) { + if (active.find(&v) != active.end()) { str << ""; return; } - seen.insert(&v); + active.insert(&v); switch (v.type) { case tInt: @@ -77,7 +77,7 @@ static void printValue(std::ostream & str, std::set & seen, const sorted[i->name] = i->value; for (auto & i : sorted) { str << i.first << " = "; - printValue(str, seen, *i.second); + printValue(str, active, *i.second); str << "; "; } str << "}"; @@ -86,7 +86,7 @@ static void printValue(std::ostream & str, std::set & seen, const case tList: str << "[ "; for (unsigned int n = 0; n < v.list.length; ++n) { - printValue(str, seen, *v.list.elems[n]); + printValue(str, active, *v.list.elems[n]); str << " "; } str << "]"; @@ -107,13 +107,15 @@ static void printValue(std::ostream & str, std::set & seen, const default: throw Error("invalid value"); } + + active.erase(&v); } std::ostream & operator << (std::ostream & str, const Value & v) { - std::set seen; - printValue(str, seen, v); + std::set active; + printValue(str, active, v); return str; }