Optimize a tight loop in FX_Number.
While doing string to int conversion:
1) Remove a redundant std::isdigit() call.
2) Don't call CheckedNumeric::IsValid() in this case.
- It's almost always valid.
- Continuing in an invalid state does not cause any security issues.
Change-Id: I4473b1ec020cd56e241276c21e35c25b5af5a144
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72250
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_number.cpp b/core/fxcrt/fx_number.cpp
index 178ede9..99e9f41 100644
--- a/core/fxcrt/fx_number.cpp
+++ b/core/fxcrt/fx_number.cpp
@@ -50,11 +50,10 @@
cc++;
}
- while (cc < strc.GetLength() && std::isdigit(strc[cc])) {
- unsigned_val = unsigned_val * 10 + FXSYS_DecimalCharToInt(strc.CharAt(cc));
- if (!unsigned_val.IsValid())
- break;
- cc++;
+ for (; cc < strc.GetLength() && std::isdigit(strc[cc]); ++cc) {
+ // Deliberately not using FXSYS_DecimalCharToInt() in a tight loop to avoid
+ // a duplicate std::isdigit() call.
+ unsigned_val = unsigned_val * 10 + strc[cc] - '0';
}
uint32_t uValue = unsigned_val.ValueOrDefault(0);