Merge pull request #33 from blackwhale/kill-filtering
Speed up token filtering
This commit is contained in:
commit
55ad8941b0
134
std/d/lexer.d
134
std/d/lexer.d
|
@ -683,30 +683,7 @@ struct TokenRange(LexSrc)
|
||||||
*/
|
*/
|
||||||
void popFront()
|
void popFront()
|
||||||
{
|
{
|
||||||
// Filter out tokens we don't care about
|
advance();
|
||||||
loop: while (true)
|
|
||||||
{
|
|
||||||
advance();
|
|
||||||
if(empty)
|
|
||||||
break loop;
|
|
||||||
switch (current.type)
|
|
||||||
{
|
|
||||||
case TokenType.whitespace:
|
|
||||||
if (config.iterStyle & IterationStyle.includeWhitespace)
|
|
||||||
break loop;
|
|
||||||
break;
|
|
||||||
case TokenType.comment:
|
|
||||||
if (config.iterStyle & IterationStyle.includeComments)
|
|
||||||
break loop;
|
|
||||||
break;
|
|
||||||
case TokenType.specialTokenSequence:
|
|
||||||
if (config.iterStyle & IterationStyle.includeSpecialTokens)
|
|
||||||
break loop;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -716,6 +693,7 @@ private:
|
||||||
*/
|
*/
|
||||||
void advance()
|
void advance()
|
||||||
{
|
{
|
||||||
|
L_advance:
|
||||||
if (src.empty)
|
if (src.empty)
|
||||||
{
|
{
|
||||||
_empty = true;
|
_empty = true;
|
||||||
|
@ -809,10 +787,10 @@ private:
|
||||||
case '*':
|
case '*':
|
||||||
case '+':
|
case '+':
|
||||||
if (config.iterStyle & IterationStyle.includeComments)
|
if (config.iterStyle & IterationStyle.includeComments)
|
||||||
lexComment!true();
|
return lexComment!true();
|
||||||
else
|
lexComment!false();
|
||||||
lexComment!false();
|
goto L_advance; // tail-recursion
|
||||||
return;
|
|
||||||
case '=':
|
case '=':
|
||||||
current.type = TokenType.divEquals;
|
current.type = TokenType.divEquals;
|
||||||
current.value = "/=";
|
current.value = "/=";
|
||||||
|
@ -901,20 +879,24 @@ private:
|
||||||
else
|
else
|
||||||
goto default;
|
goto default;
|
||||||
case '#':
|
case '#':
|
||||||
lexSpecialTokenSequence();
|
lexSpecialTokenSequence();
|
||||||
return;
|
if(config.iterStyle & IterationStyle.includeSpecialTokens)
|
||||||
|
return;
|
||||||
|
goto L_advance; // tail-recursion
|
||||||
// "short" ASCII whites
|
// "short" ASCII whites
|
||||||
case 0x20:
|
case 0x20:
|
||||||
case 0x09: .. case 0x0d:
|
case 0x09: .. case 0x0d:
|
||||||
if (config.iterStyle & IterationStyle.includeWhitespace)
|
if (config.iterStyle & IterationStyle.includeWhitespace)
|
||||||
return lexWhitespace!true();
|
return lexWhitespace!true();
|
||||||
return lexWhitespace!false();
|
lexWhitespace!false();
|
||||||
|
goto L_advance; // tail-recursion
|
||||||
default:
|
default:
|
||||||
if ((src.front & 0x80) && isLongWhite())
|
if ((src.front & 0x80) && isLongWhite())
|
||||||
{
|
{
|
||||||
if (config.iterStyle & IterationStyle.includeWhitespace)
|
if (config.iterStyle & IterationStyle.includeWhitespace)
|
||||||
return lexWhitespace!true();
|
return lexWhitespace!true();
|
||||||
return lexWhitespace!false();
|
lexWhitespace!false();
|
||||||
|
goto L_advance; // tail-recursion
|
||||||
}
|
}
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
@ -936,48 +918,9 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(config.iterStyle & TokenStyle.doNotReplaceSpecial))
|
if (config.iterStyle & TokenStyle.doNotReplaceSpecial)
|
||||||
return;
|
return;
|
||||||
|
expandSpecialToken();
|
||||||
switch (current.type)
|
|
||||||
{
|
|
||||||
case TokenType.date:
|
|
||||||
current.type = TokenType.stringLiteral;
|
|
||||||
auto time = Clock.currTime();
|
|
||||||
current.value = format("%s %02d %04d", time.month, time.day, time.year);
|
|
||||||
return;
|
|
||||||
case TokenType.time:
|
|
||||||
auto time = Clock.currTime();
|
|
||||||
current.type = TokenType.stringLiteral;
|
|
||||||
current.value = (cast(TimeOfDay)(time)).toISOExtString();
|
|
||||||
return;
|
|
||||||
case TokenType.timestamp:
|
|
||||||
auto time = Clock.currTime();
|
|
||||||
auto dt = cast(DateTime) time;
|
|
||||||
current.type = TokenType.stringLiteral;
|
|
||||||
current.value = format("%s %s %02d %02d:%02d:%02d %04d",
|
|
||||||
dt.dayOfWeek, dt.month, dt.day, dt.hour, dt.minute,
|
|
||||||
dt.second, dt.year);
|
|
||||||
return;
|
|
||||||
case TokenType.vendor:
|
|
||||||
current.type = TokenType.stringLiteral;
|
|
||||||
current.value = config.vendorString;
|
|
||||||
return;
|
|
||||||
case TokenType.compilerVersion:
|
|
||||||
current.type = TokenType.stringLiteral;
|
|
||||||
current.value = format("%d", config.versionNumber);
|
|
||||||
return;
|
|
||||||
case TokenType.line:
|
|
||||||
current.type = TokenType.intLiteral;
|
|
||||||
current.value = format("%d", current.line);
|
|
||||||
return;
|
|
||||||
case TokenType.file:
|
|
||||||
current.type = TokenType.stringLiteral;
|
|
||||||
current.value = config.fileName;
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2144,10 +2087,53 @@ private:
|
||||||
else
|
else
|
||||||
r.popFront();
|
r.popFront();
|
||||||
if (r.empty || (r.front != 0xa8 && r.front != 0xa9))
|
if (r.empty || (r.front != 0xa8 && r.front != 0xa9))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void expandSpecialToken()
|
||||||
|
{
|
||||||
|
switch (current.type)
|
||||||
|
{
|
||||||
|
case TokenType.date:
|
||||||
|
current.type = TokenType.stringLiteral;
|
||||||
|
auto time = Clock.currTime();
|
||||||
|
current.value = format("%s %02d %04d", time.month, time.day, time.year);
|
||||||
|
return;
|
||||||
|
case TokenType.time:
|
||||||
|
auto time = Clock.currTime();
|
||||||
|
current.type = TokenType.stringLiteral;
|
||||||
|
current.value = (cast(TimeOfDay)(time)).toISOExtString();
|
||||||
|
return;
|
||||||
|
case TokenType.timestamp:
|
||||||
|
auto time = Clock.currTime();
|
||||||
|
auto dt = cast(DateTime) time;
|
||||||
|
current.type = TokenType.stringLiteral;
|
||||||
|
current.value = format("%s %s %02d %02d:%02d:%02d %04d",
|
||||||
|
dt.dayOfWeek, dt.month, dt.day, dt.hour, dt.minute,
|
||||||
|
dt.second, dt.year);
|
||||||
|
return;
|
||||||
|
case TokenType.vendor:
|
||||||
|
current.type = TokenType.stringLiteral;
|
||||||
|
current.value = config.vendorString;
|
||||||
|
return;
|
||||||
|
case TokenType.compilerVersion:
|
||||||
|
current.type = TokenType.stringLiteral;
|
||||||
|
current.value = format("%d", config.versionNumber);
|
||||||
|
return;
|
||||||
|
case TokenType.line:
|
||||||
|
current.type = TokenType.intLiteral;
|
||||||
|
current.value = format("%d", current.line);
|
||||||
|
return;
|
||||||
|
case TokenType.file:
|
||||||
|
current.type = TokenType.stringLiteral;
|
||||||
|
current.value = config.fileName;
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void errorMessage(string s)
|
void errorMessage(string s)
|
||||||
{
|
{
|
||||||
import std.string: format;
|
import std.string: format;
|
||||||
|
|
Loading…
Reference in New Issue