[PATCH] D43892: [YAML] speed up isNumber by doing regex matching less often
Dean Michael Berris via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 18:23:39 PST 2018
dberris added inline comments.
Comment at: include/llvm/Support/YAMLTraits.h:479-480
- return false;
+ Regex FloatMatcher("^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
+ return FloatMatcher.match(S);
> dberris wrote:
> > Does it make sense to make the `Regex` object `static` and `const` so that we only compile/initialise it once?
> I was too lazy to look into Regex implementation to check whether it actually makes sense. I bet the current version is faster though.
Why would this be faster than having it compiled once, and only the first time it's needed?
I suspect if you do that, instead of having to do a linear search first, would be much faster if it's possible to re-use a Regex object, compile it once, and re-use for all the times it's needed.
More information about the llvm-commits