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; allowSimpleKey_ = false;
// Scan and add SCALAR. // 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. ///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. /// 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 startMark = reader_.mark;
const quote = reader_.get(); const quote = reader_.get();
reader_.sliceBuilder.begin(); reader_.sliceBuilder.begin();
//XXX remove once nothrow scope(exit) if(error_) { reader_.sliceBuilder.finish(); }
scope(failure) { reader_.sliceBuilder.finish(); }
scope(exit) { if(error_) {reader_.sliceBuilder.finish();}}
scanFlowScalarNonSpacesToSlice(quotes, startMark); scanFlowScalarNonSpacesToSlice(quotes, startMark);
throwIfError(); if(error_) { return Token.init; }
while(reader_.peek() != quote) while(reader_.peek() != quote)
{ {
scanFlowScalarSpacesToSlice(startMark); scanFlowScalarSpacesToSlice(startMark);
throwIfError(); if(error_) { return Token.init; }
scanFlowScalarNonSpacesToSlice(quotes, startMark); scanFlowScalarNonSpacesToSlice(quotes, startMark);
throwIfError(); if(error_) { return Token.init; }
} }
reader_.forward(); reader_.forward();