[PATCH] D43892: [YAML] speed up isNumber by doing regex matching less often
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 10:20:46 PST 2018
zturner 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:
> pelikan wrote:
> > 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.
Agree, this will make the case where it's not a number faster, but that's the uncommon case. The case where it *is* a number will become slower. I agree with Dean's suggestion of compiling the regex only once, but we can still do an early out if it's obviously not a number. However, instead of checking the entire string, how about just checking the first character?
Repository:
rL LLVM
https://reviews.llvm.org/D43892
More information about the llvm-commits
mailing list