From 77c223be193b303b833053a757a2f1f2534da610 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 14 May 2018 18:24:40 +0000 Subject: Use internal wcstof instead of system wcstod in formcalc lexer This CL switches the usage of wcstod to use the FXSYS_wcstof to determine if a given string is a valid floating point number. Using the internal method makes linux slightly slower (10's of ms) makes mac a lot faster 900ms to 60ms for the test case in the bug. The FXSYS_wcstof method has been extended to handle the parsing of float exponents. Unittests were added for FXSYS_wcstof. Bug: chromium:813646 Change-Id: Ie68287a336e3b95a0c0b845d5bf39db6fc82b39c Reviewed-on: https://pdfium-review.googlesource.com/32510 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- core/fxcrt/fx_extension.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'core/fxcrt/fx_extension.cpp') diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 83aee86316..b1f2a95d62 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -50,6 +50,38 @@ float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { fPrecise *= 0.1f; } } + + if (iUsedLen < iLength && + (pwsStr[iUsedLen] == 'e' || pwsStr[iUsedLen] == 'E')) { + ++iUsedLen; + + bool negative_exponent = false; + if (iUsedLen < iLength && + (pwsStr[iUsedLen] == '-' || pwsStr[iUsedLen] == '+')) { + negative_exponent = pwsStr[iUsedLen] == '-'; + ++iUsedLen; + } + + size_t exp_value = 0; + while (iUsedLen < iLength) { + wchar_t wch = pwsStr[iUsedLen]; + if (!std::iswdigit(wch)) + break; + + exp_value = exp_value * 10.0f + (wch - L'0'); + ++iUsedLen; + } + + for (size_t i = exp_value; i > 0; --i) { + if (exp_value > 0) { + if (negative_exponent) + fValue /= 10; + else + fValue *= 10; + } + } + } + if (pUsedLen) *pUsedLen = iUsedLen; -- cgit v1.2.3