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

@ -718,8 +718,10 @@ final class Scanner
//No simple keys after flow scalars. //No simple keys after flow scalars.
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();