assumeSafeAppend to decrease GC usage.
This commit is contained in:
parent
7fa53704c5
commit
4a76d4b886
|
@ -309,7 +309,11 @@ final class Composer
|
||||||
Node[] toMerge;
|
Node[] toMerge;
|
||||||
foreach(ref Node key, ref Node value; root)
|
foreach(ref Node key, ref Node value; root)
|
||||||
{
|
{
|
||||||
if(key.isType!YAMLMerge){toMerge ~= value;}
|
if(key.isType!YAMLMerge)
|
||||||
|
{
|
||||||
|
toMerge.assumeSafeAppend();
|
||||||
|
toMerge ~= value;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto temp = Node.Pair(key, value);
|
auto temp = Node.Pair(key, value);
|
||||||
|
|
|
@ -693,8 +693,9 @@ Node.Pair[] getPairs(string type, Node[] nodes)
|
||||||
{
|
{
|
||||||
enforce(node.isMapping && node.length == 1,
|
enforce(node.isMapping && node.length == 1,
|
||||||
new Exception("While constructing " ~ type ~
|
new Exception("While constructing " ~ type ~
|
||||||
", expected a mapping with single element"));
|
", expected a mapping with single element"));
|
||||||
|
|
||||||
|
pairs.assumeSafeAppend();
|
||||||
pairs ~= node.as!(Node.Pair[]);
|
pairs ~= node.as!(Node.Pair[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,8 +731,8 @@ unittest
|
||||||
Node[] pairs;
|
Node[] pairs;
|
||||||
foreach(long i; 0 .. length)
|
foreach(long i; 0 .. length)
|
||||||
{
|
{
|
||||||
auto pair = (i % 2) ? Pair(to!string(i), i)
|
auto pair = (i % 2) ? Pair(i.to!string, i) : Pair(i, i.to!string);
|
||||||
: Pair(i, to!string(i));
|
pairs.assumeSafeAppend();
|
||||||
pairs ~= Node([pair]);
|
pairs ~= Node([pair]);
|
||||||
}
|
}
|
||||||
return pairs;
|
return pairs;
|
||||||
|
@ -742,7 +743,8 @@ unittest
|
||||||
Node[] pairs;
|
Node[] pairs;
|
||||||
foreach(long i; 0 .. length)
|
foreach(long i; 0 .. length)
|
||||||
{
|
{
|
||||||
auto pair = Pair(to!string(i), i);
|
auto pair = Pair(i.to!string, i);
|
||||||
|
pairs.assumeSafeAppend();
|
||||||
pairs ~= Node([pair]);
|
pairs ~= Node([pair]);
|
||||||
}
|
}
|
||||||
return pairs;
|
return pairs;
|
||||||
|
@ -781,9 +783,9 @@ Node[] constructSet(ref Node node)
|
||||||
Node[] nodes;
|
Node[] nodes;
|
||||||
foreach(ref pair; pairs)
|
foreach(ref pair; pairs)
|
||||||
{
|
{
|
||||||
enforce((pair.key in map) is null,
|
enforce((pair.key in map) is null, new Exception("Duplicate entry in a set"));
|
||||||
new Exception("Duplicate entry in a set"));
|
|
||||||
map[pair.key] = 0;
|
map[pair.key] = 0;
|
||||||
|
nodes.assumeSafeAppend();
|
||||||
nodes ~= pair.key;
|
nodes ~= pair.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,7 +800,8 @@ unittest
|
||||||
Node.Pair[] pairs;
|
Node.Pair[] pairs;
|
||||||
foreach(long i; 0 .. length)
|
foreach(long i; 0 .. length)
|
||||||
{
|
{
|
||||||
pairs ~= Node.Pair(to!string(i), YAMLNull());
|
pairs.assumeSafeAppend();
|
||||||
|
pairs ~= Node.Pair(i.to!string, YAMLNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
return pairs;
|
return pairs;
|
||||||
|
|
Loading…
Reference in a new issue