assumeSafeAppend to decrease GC usage.

This commit is contained in:
Ferdinand Majerech 2014-07-19 01:59:26 +02:00
parent 7fa53704c5
commit 4a76d4b886
2 changed files with 15 additions and 8 deletions

View file

@ -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);

View file

@ -695,6 +695,7 @@ Node.Pair[] getPairs(string type, Node[] nodes)
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;