From d4d645abecec0fe2e6477b5928cfa2967675585b Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 25 May 2018 20:12:39 +0000 Subject: Reserve space for code words when creating encoder context During encoding, the code is going to walk through every character in m_msg and determine what values need to be added to m_codewords. The ceiling on the number of characters being added to m_codewords is the length of m_msg, so reserving enought space in advance. This prevents thrash related to incrementing the string and thus resizing in a tight loop. BUG=chromium:846027 Change-Id: Icefd6955933f8068feeeee6243e430f60c50d747 Reviewed-on: https://pdfium-review.googlesource.com/32990 Reviewed-by: Lei Zhang Commit-Queue: Ryan Harrison --- fxbarcode/datamatrix/BC_EncoderContext.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/fxbarcode/datamatrix/BC_EncoderContext.cpp b/fxbarcode/datamatrix/BC_EncoderContext.cpp index d9823bffe2..f5c2f4c1fc 100644 --- a/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ b/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -44,6 +44,7 @@ CBC_EncoderContext::CBC_EncoderContext(const WideString& msg, sb += ch; } m_msg = sb; + m_codewords.Reserve(m_msg.GetLength()); m_allowRectangular = true; m_newEncoding = -1; m_pos = 0; -- cgit v1.2.3