[PATCH] D50839: [llvm] Optimize YAML::isNumeric

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 17 07:47:45 PDT 2018


zturner added inline comments.


================
Comment at: llvm/include/llvm/Support/YAMLTraits.h:458
+    ++Digits;
+  return S.drop_front(Digits);
+}
----------------
ilya-biryukov wrote:
> - Maybe simplify to `return S.dropWhile(...)`?
> - Maybe make it a lambda and put inside `isNumeric`?
`dropWhile` will probably be slower, but `S.drop_front(S.find_first_not_of("0123456789"))` would be good


================
Comment at: llvm/include/llvm/Support/YAMLTraits.h:482-483
+  if (S.startswith("0o"))
+    return S.size() > 2 &&
+           S.drop_front(2).find_first_not_of("01234567") == StringRef::npos;
+
----------------
Doesn't `find_first_not_of` have a starting pos argument?  If so we could use that instead of the `drop_front`


================
Comment at: llvm/include/llvm/Support/YAMLTraits.h:487-488
+    return S.size() > 2 &&
+           S.drop_front(2).find_first_not_of("0123456789abcdefABCDEF") ==
+             StringRef::npos;
+
----------------
Same here.


================
Comment at: llvm/include/llvm/Support/YAMLTraits.h:497
+  if (S.startswith(".") &&
+      (S.equals(".") || (S.size() > 1 && std::strchr("0123456789",
+                                                     S[1]) == nullptr)))
----------------
ilya-biryukov wrote:
> maybe use `std::isdigit(S[1])` instead?
We should use `llvm::isDigit` instead.


https://reviews.llvm.org/D50839





More information about the llvm-commits mailing list