scanFlowScalar is now nothrow and only does one GC allocation.

This commit is contained in:
Ferdinand Majerech 2014-07-24 23:21:59 +02:00
parent a59a34ffce
commit 4ed4a2c746

View file

@ -719,7 +719,9 @@ final class Scanner
allowSimpleKey_ = false;
// Scan and add SCALAR.
tokens_.push(scanFlowScalar(quotes));
const scalar = scanFlowScalar(quotes);
throwIfError();
tokens_.push(scalar);
}
///Aliases to add single or double quoted block scalar.
@ -1282,24 +1284,25 @@ final class Scanner
}
/// Scan a qouted flow scalar token with specified quotes.
Token scanFlowScalar(const ScalarStyle quotes) @trusted pure
///
/// In case of an error, error_ is set. Check this before using the result.
Token scanFlowScalar(const ScalarStyle quotes) @trusted pure nothrow
{
const startMark = reader_.mark;
const quote = reader_.get();
reader_.sliceBuilder.begin();
//XXX remove once nothrow
scope(failure) { reader_.sliceBuilder.finish(); }
scope(exit) { if(error_) {reader_.sliceBuilder.finish();}}
scope(exit) if(error_) { reader_.sliceBuilder.finish(); }
scanFlowScalarNonSpacesToSlice(quotes, startMark);
throwIfError();
if(error_) { return Token.init; }
while(reader_.peek() != quote)
{
scanFlowScalarSpacesToSlice(startMark);
throwIfError();
if(error_) { return Token.init; }
scanFlowScalarNonSpacesToSlice(quotes, startMark);
throwIfError();
if(error_) { return Token.init; }
}
reader_.forward();