diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-21T19·25+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-21T19·25+0000 |
commit | 6bbfe95e3012effa0df79066ae129ce9828a8ff2 (patch) | |
tree | 86e3b4cae2a82e78ba0c6593d50d7c4a03ddd2ad /src | |
parent | 7148df797174ff742fdd8cee3c2d92e6340ee930 (diff) |
* Don't use an ostringstream in unparseDerivation(), because it's
slow. A `nix-env -qa --drv-path \*' on Nixpkgs was spending 40% of its time in unparseDerivation() because of this (now 11%).
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/derivations.cc | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 3d0f1eb4247b..e321ae8aaee6 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -92,75 +92,76 @@ Derivation parseDerivation(const string & s) } -void printString(std::ostream & str, const string & s) +static void printString(string & res, const string & s) { - str << "\""; + res += '"'; for (const char * i = s.c_str(); *i; i++) - if (*i == '\"' || *i == '\\') str << "\\" << *i; - else if (*i == '\n') str << "\\n"; - else if (*i == '\r') str << "\\r"; - else if (*i == '\t') str << "\\t"; - else str << *i; - str << "\""; + if (*i == '\"' || *i == '\\') { res += "\\"; res += *i; } + else if (*i == '\n') res += "\\n"; + else if (*i == '\r') res += "\\r"; + else if (*i == '\t') res += "\\t"; + else res += *i; + res += '"'; } template<class ForwardIterator> -void printStrings(std::ostream & str, ForwardIterator i, ForwardIterator j) +static void printStrings(string & res, ForwardIterator i, ForwardIterator j) { - str << "["; + res += '['; bool first = true; for ( ; i != j; ++i) { - if (first) first = false; else str << ","; - printString(str, *i); + if (first) first = false; else res += ','; + printString(res, *i); } - str << "]"; + res += ']'; } string unparseDerivation(const Derivation & drv) { - std::ostringstream str; - str << "Derive(["; + string s; + s.reserve(65536); + s += "Derive(["; bool first = true; foreach (DerivationOutputs::const_iterator, i, drv.outputs) { - if (first) first = false; else str << ","; - str << "("; printString(str, i->first); - str << ","; printString(str, i->second.path); - str << ","; printString(str, i->second.hashAlgo); - str << ","; printString(str, i->second.hash); - str << ")"; + if (first) first = false; else s += ','; + s += '('; printString(s, i->first); + s += ','; printString(s, i->second.path); + s += ','; printString(s, i->second.hashAlgo); + s += ','; printString(s, i->second.hash); + s += ')'; } - str << "],["; + s += "],["; first = true; foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) { - if (first) first = false; else str << ","; - str << "("; printString(str, i->first); - str << ","; printStrings(str, i->second.begin(), i->second.end()); - str << ")"; + if (first) first = false; else s += ','; + s += '('; printString(s, i->first); + s += ','; printStrings(s, i->second.begin(), i->second.end()); + s += ')'; } - str << "],"; - printStrings(str, drv.inputSrcs.begin(), drv.inputSrcs.end()); + s += "],"; + printStrings(s, drv.inputSrcs.begin(), drv.inputSrcs.end()); - str << ","; printString(str, drv.platform); - str << ","; printString(str, drv.builder); - str << ","; printStrings(str, drv.args.begin(), drv.args.end()); + s += ','; printString(s, drv.platform); + s += ','; printString(s, drv.builder); + s += ','; printStrings(s, drv.args.begin(), drv.args.end()); - str << ",["; + s += ",["; first = true; foreach (StringPairs::const_iterator, i, drv.env) { - if (first) first = false; else str << ","; - str << "("; printString(str, i->first); - str << ","; printString(str, i->second); - str << ")"; + if (first) first = false; else s += ','; + s += '('; printString(s, i->first); + s += ','; printString(s, i->second); + s += ')'; } - str << "])"; + s += "])"; - return str.str(); + return s; } |