From e90469e4c9b22ff912c70ec70392cf607fb1ad57 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 14 Jun 2018 19:55:22 +0000 Subject: [formcalc] Calculate length of string when calling FXSYS_wcstof When calling the FXSYS_wctof method we currently pass in -1 from AdvanceForNumber. This tells the method to calculate the string length. This can be slow for a formcalc string with a lot of numbers. This CL changes the call to pass in the length of remaining data in the original string. This takes the MSAN runtime of the case in the linked bug from ~21seconds to ~500ms. The debug runtime goes from ~2s to ~500ms. Bug: chromium:846104 Change-Id: Idbd19a728160f35982e21c0d97567fbbeefe667a Reviewed-on: https://pdfium-review.googlesource.com/35210 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fxfa/fm2js/cxfa_fmlexer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp index 3a694675b7..f9771940b6 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp @@ -304,8 +304,10 @@ CXFA_FMToken CXFA_FMLexer::NextToken() { CXFA_FMToken CXFA_FMLexer::AdvanceForNumber() { // This will set end to the character after the end of the number. int32_t used_length = 0; - if (m_cursor) - FXSYS_wcstof(const_cast(m_cursor), -1, &used_length); + if (m_cursor) { + FXSYS_wcstof(const_cast(m_cursor), m_end - m_cursor, + &used_length); + } const wchar_t* end = m_cursor + used_length; if (used_length == 0 || !end || FXSYS_iswalpha(*end)) { -- cgit v1.2.3