[PATCH] D43892: [YAML] speed up isNumber by doing regex matching less often
Martin Pelikán via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 18:09:03 PST 2018
pelikan updated this revision to Diff 136453.
pelikan added a comment.
sync
Repository:
rL LLVM
https://reviews.llvm.org/D43892
Files:
include/llvm/Support/YAMLTraits.h
Index: include/llvm/Support/YAMLTraits.h
===================================================================
--- include/llvm/Support/YAMLTraits.h
+++ include/llvm/Support/YAMLTraits.h
@@ -471,11 +471,13 @@
if (S.equals(".inf") || S.equals(".Inf") || S.equals(".INF"))
return true;
- Regex FloatMatcher("^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
- if (FloatMatcher.match(S))
- return true;
+ // Don't waste time regex matching on anything obviously non-numeric.
+ static const char FloatChars[] = "+-0123456789.eE";
+ if (S.find_first_not_of(FloatChars) != StringRef::npos)
+ return false;
- return false;
+ Regex FloatMatcher("^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
+ return FloatMatcher.match(S);
}
inline bool isNumeric(StringRef S) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43892.136453.patch
Type: text/x-patch
Size: 795 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180301/1a7a5760/attachment.bin>
More information about the llvm-commits
mailing list