From 4961cb163fb36b8e3ce1babbcf851ee4285dd031 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Sat, 19 Jul 2014 14:49:13 +0200 Subject: [PATCH] assumeSafeAppend in Loader functions to reduce GC usage. --- source/dyaml/loader.d | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/dyaml/loader.d b/source/dyaml/loader.d index c74710b..f0de9d4 100644 --- a/source/dyaml/loader.d +++ b/source/dyaml/loader.d @@ -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;