Commit 8c35a8ff authored by Scott Wolchok's avatar Scott Wolchok Committed by Jesse Beder
Browse files

Cache scalar regexes

This improves performance on the test.yaml attached to #158 by about
35% on my machine (0.39s -> 0.25s), as measured by
`time build/util/parse < test.yaml > /dev/null`.
parent 9e37409b
...@@ -165,6 +165,15 @@ inline const RegEx& EndScalarInFlow() { ...@@ -165,6 +165,15 @@ inline const RegEx& EndScalarInFlow() {
return e; return e;
} }
inline const RegEx& ScanScalarEndInFlow() {
static const RegEx e = (EndScalarInFlow() || (BlankOrBreak() + Comment()));
return e;
}
inline const RegEx& ScanScalarEnd() {
static const RegEx e = EndScalar() || (BlankOrBreak() + Comment());
return e;
}
inline const RegEx& EscSingleQuote() { inline const RegEx& EscSingleQuote() {
static const RegEx e = RegEx("\'\'"); static const RegEx e = RegEx("\'\'");
return e; return e;
......
...@@ -297,8 +297,8 @@ void Scanner::ScanPlainScalar() { ...@@ -297,8 +297,8 @@ void Scanner::ScanPlainScalar() {
// set up the scanning parameters // set up the scanning parameters
ScanScalarParams params; ScanScalarParams params;
params.end = (InFlowContext() ? Exp::EndScalarInFlow() : Exp::EndScalar()) || params.end =
(Exp::BlankOrBreak() + Exp::Comment()); (InFlowContext() ? Exp::ScanScalarEndInFlow() : Exp::ScanScalarEnd());
params.eatEnd = false; params.eatEnd = false;
params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1); params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1);
params.fold = FOLD_FLOW; params.fold = FOLD_FLOW;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment