assumeSafeAppend in Loader functions to reduce GC usage.

This commit is contained in:
Ferdinand Majerech 2014-07-19 14:49:13 +02:00
parent a7f5aa1cf2
commit 4961cb163f

View file

@ -224,10 +224,14 @@ struct Loader
/// Returns: Array of root nodes of all documents in the file/stream.
///
/// Throws: YAMLException on a parsing error.
Node[] loadAll() @safe
Node[] loadAll() @trusted
{
Node[] nodes;
foreach(ref node; this) {nodes ~= node;}
foreach(ref node; this)
{
nodes.assumeSafeAppend();
nodes ~= node;
}
return nodes;
}
@ -269,13 +273,14 @@ struct Loader
package:
// Scan and return all tokens. Used for debugging.
Token[] scan() @safe
Token[] scan() @trusted
{
try
{
Token[] result;
while(scanner_.checkToken())
{
result.assumeSafeAppend();
result ~= scanner_.getToken();
}
return result;