Merge pull request #252 from Herringway/undo-false-optimizations

undo some false optimizations
merged-on-behalf-of: Cameron Ross <elpenguino@gmail.com>
This commit is contained in:
The Dlang Bot 2020-05-07 19:58:05 +02:00 committed by GitHub
commit 0b92d5a2f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1362,28 +1362,9 @@ struct Scanner
dchar c = reader_.peek();
size_t numCodePoints;
// This is an optimized way of writing:
// while(!search.canFind(reader_.peek(numCodePoints))) { ++numCodePoints; }
outer: for(size_t oldSliceLength;;)
{
// This will not necessarily make slice 32 chars longer, as not all
// code points are 1 char.
const char[] slice = reader_.slice(numCodePoints + 32);
enforce(slice.length != oldSliceLength,
new ScannerException("While reading a flow scalar", startMark,
"reached end of file", reader_.mark));
while(!reader_.peek(numCodePoints).isFlowScalarBreakSpace) { ++numCodePoints; }
for(size_t i = oldSliceLength; i < slice.length;)
{
// slice is UTF-8 - need to decode
const ch = slice[i] < 0x80 ? slice[i++] : decode(slice, i);
if(ch.isFlowScalarBreakSpace) { break outer; }
++numCodePoints;
}
oldSliceLength = slice.length;
}
reader_.sliceBuilder.write(reader_.get(numCodePoints));
if (numCodePoints > 0) { reader_.sliceBuilder.write(reader_.get(numCodePoints)); }
c = reader_.peek();
if(quotes == ScalarStyle.singleQuoted && c == '\'' && reader_.peek(1) == '\'')
@ -1540,34 +1521,18 @@ struct Scanner
{
// Scan the entire plain scalar.
size_t length;
dchar c = void;
// Moved the if() out of the loop for optimization.
if(flowLevel_ == 0)
dchar c = reader_.peek(length);
for(;;)
{
c = reader_.peek(length);
for(;;)
const cNext = reader_.peek(length + 1);
if(c.isWhiteSpace ||
(flowLevel_ == 0 && c == ':' && cNext.isWhiteSpace) ||
(flowLevel_ > 0 && c.among!(',', ':', '?', '[', ']', '{', '}')))
{
const cNext = reader_.peek(length + 1);
if(c.isWhiteSpace ||
(c == ':' && cNext.isWhiteSpace))
{
break;
}
++length;
c = cNext;
}
}
else
{
for(;;)
{
c = reader_.peek(length);
if(c.isWhiteSpace || c.among!(',', ':', '?', '[', ']', '{', '}'))
{
break;
}
++length;
break;
}
++length;
c = cNext;
}
// It's not clear what we should do with ':' in the flow context.