forked from lix-project/lix
* 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%).
This commit is contained in:
parent
7148df7971
commit
6bbfe95e30
|
@ -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++)
|
for (const char * i = s.c_str(); *i; i++)
|
||||||
if (*i == '\"' || *i == '\\') str << "\\" << *i;
|
if (*i == '\"' || *i == '\\') { res += "\\"; res += *i; }
|
||||||
else if (*i == '\n') str << "\\n";
|
else if (*i == '\n') res += "\\n";
|
||||||
else if (*i == '\r') str << "\\r";
|
else if (*i == '\r') res += "\\r";
|
||||||
else if (*i == '\t') str << "\\t";
|
else if (*i == '\t') res += "\\t";
|
||||||
else str << *i;
|
else res += *i;
|
||||||
str << "\"";
|
res += '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class ForwardIterator>
|
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;
|
bool first = true;
|
||||||
for ( ; i != j; ++i) {
|
for ( ; i != j; ++i) {
|
||||||
if (first) first = false; else str << ",";
|
if (first) first = false; else res += ',';
|
||||||
printString(str, *i);
|
printString(res, *i);
|
||||||
}
|
}
|
||||||
str << "]";
|
res += ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string unparseDerivation(const Derivation & drv)
|
string unparseDerivation(const Derivation & drv)
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
string s;
|
||||||
str << "Derive([";
|
s.reserve(65536);
|
||||||
|
s += "Derive([";
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
foreach (DerivationOutputs::const_iterator, i, drv.outputs) {
|
foreach (DerivationOutputs::const_iterator, i, drv.outputs) {
|
||||||
if (first) first = false; else str << ",";
|
if (first) first = false; else s += ',';
|
||||||
str << "("; printString(str, i->first);
|
s += '('; printString(s, i->first);
|
||||||
str << ","; printString(str, i->second.path);
|
s += ','; printString(s, i->second.path);
|
||||||
str << ","; printString(str, i->second.hashAlgo);
|
s += ','; printString(s, i->second.hashAlgo);
|
||||||
str << ","; printString(str, i->second.hash);
|
s += ','; printString(s, i->second.hash);
|
||||||
str << ")";
|
s += ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
str << "],[";
|
s += "],[";
|
||||||
first = true;
|
first = true;
|
||||||
foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) {
|
foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) {
|
||||||
if (first) first = false; else str << ",";
|
if (first) first = false; else s += ',';
|
||||||
str << "("; printString(str, i->first);
|
s += '('; printString(s, i->first);
|
||||||
str << ","; printStrings(str, i->second.begin(), i->second.end());
|
s += ','; printStrings(s, i->second.begin(), i->second.end());
|
||||||
str << ")";
|
s += ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
str << "],";
|
s += "],";
|
||||||
printStrings(str, drv.inputSrcs.begin(), drv.inputSrcs.end());
|
printStrings(s, drv.inputSrcs.begin(), drv.inputSrcs.end());
|
||||||
|
|
||||||
str << ","; printString(str, drv.platform);
|
s += ','; printString(s, drv.platform);
|
||||||
str << ","; printString(str, drv.builder);
|
s += ','; printString(s, drv.builder);
|
||||||
str << ","; printStrings(str, drv.args.begin(), drv.args.end());
|
s += ','; printStrings(s, drv.args.begin(), drv.args.end());
|
||||||
|
|
||||||
str << ",[";
|
s += ",[";
|
||||||
first = true;
|
first = true;
|
||||||
foreach (StringPairs::const_iterator, i, drv.env) {
|
foreach (StringPairs::const_iterator, i, drv.env) {
|
||||||
if (first) first = false; else str << ",";
|
if (first) first = false; else s += ',';
|
||||||
str << "("; printString(str, i->first);
|
s += '('; printString(s, i->first);
|
||||||
str << ","; printString(str, i->second);
|
s += ','; printString(s, i->second);
|
||||||
str << ")";
|
s += ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
str << "])";
|
s += "])";
|
||||||
|
|
||||||
return str.str();
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue