diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-08-15 10:37:59 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-15 15:03:10 +0000 |
commit | 8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch) | |
tree | 82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /fxbarcode/datamatrix | |
parent | 171cb27a720036c48ae3a6176084e880742af0a9 (diff) | |
download | pdfium-8a1758bf11c2d741e0cddc761b1dd2cdf564db93.tar.xz |
Remove GetAt from string classes
This method duplicates the behaviour of the const [] operator and
doesn't offer any additional safety. Folding them into one
implementation.
SetAt is retained, since implementing the non-const [] operator to
replace SetAt has potential performance concerns. Specifically many
non-obvious cases of reading an element using [] will cause a realloc
& copy.
BUG=pdfium:860
Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67
Reviewed-on: https://pdfium-review.googlesource.com/10870
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxbarcode/datamatrix')
-rw-r--r-- | fxbarcode/datamatrix/BC_ASCIIEncoder.cpp | 4 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_Base256Encoder.cpp | 14 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_C40Encoder.cpp | 6 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_DefaultPlacement.cpp | 2 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_EdifactEncoder.cpp | 8 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_EncoderContext.cpp | 8 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_ErrorCorrection.cpp | 6 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_HighLevelEncoder.cpp | 8 |
8 files changed, 28 insertions, 28 deletions
diff --git a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp index de57d81b71..e6b7a2b35b 100644 --- a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp +++ b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp @@ -37,8 +37,8 @@ void CBC_ASCIIEncoder::Encode(CBC_EncoderContext& context, int32_t& e) { int32_t n = CBC_HighLevelEncoder::determineConsecutiveDigitCount( context.m_msg, context.m_pos); if (n >= 2) { - wchar_t code = encodeASCIIDigits(context.m_msg.GetAt(context.m_pos), - context.m_msg.GetAt(context.m_pos + 1), e); + wchar_t code = encodeASCIIDigits(context.m_msg[context.m_pos], + context.m_msg[context.m_pos + 1], e); if (e != BCExceptionNO) { return; } diff --git a/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/fxbarcode/datamatrix/BC_Base256Encoder.cpp index edcd411114..0cbd3fdb10 100644 --- a/fxbarcode/datamatrix/BC_Base256Encoder.cpp +++ b/fxbarcode/datamatrix/BC_Base256Encoder.cpp @@ -35,7 +35,7 @@ int32_t CBC_Base256Encoder::getEncodingMode() { } void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { CFX_WideString buffer; - buffer += (wchar_t)'\0'; + buffer += L'\0'; while (context.hasMoreCharacters()) { wchar_t c = context.getCurrentChar(); buffer += c; @@ -50,7 +50,7 @@ void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { int32_t dataCount = buffer.GetLength() - 1; char buf[128]; FXSYS_itoa(dataCount, buf, 10); - buffer.SetAt(0, wchar_t(*buf) - '0'); + buffer.SetAt(0, static_cast<wchar_t>(*buf) - '0'); int32_t lengthFieldSize = 1; int32_t currentSize = context.getCodewordCount() + dataCount + lengthFieldSize; @@ -61,10 +61,10 @@ void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { bool mustPad = (context.m_symbolInfo->dataCapacity() - currentSize) > 0; if (context.hasMoreCharacters() || mustPad) { if (dataCount <= 249) { - buffer.SetAt(0, (wchar_t)dataCount); + buffer.SetAt(0, static_cast<wchar_t>(dataCount)); } else if (dataCount > 249 && dataCount <= 1555) { - buffer.SetAt(0, (wchar_t)((dataCount / 250) + 249)); - buffer.Insert(1, (wchar_t)(dataCount % 250)); + buffer.SetAt(0, static_cast<wchar_t>((dataCount / 250) + 249)); + buffer.Insert(1, static_cast<wchar_t>(dataCount % 250)); } else { e = BCExceptionIllegalStateMessageLengthInvalid; return; @@ -79,8 +79,8 @@ wchar_t CBC_Base256Encoder::randomize255State(wchar_t ch, int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1; int32_t tempVariable = ch + pseudoRandom; if (tempVariable <= 255) { - return (wchar_t)tempVariable; + return static_cast<wchar_t>(tempVariable); } else { - return (wchar_t)(tempVariable - 256); + return static_cast<wchar_t>(tempVariable - 256); } } diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp index 8edd9eccfe..8a55c922ed 100644 --- a/fxbarcode/datamatrix/BC_C40Encoder.cpp +++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp @@ -32,9 +32,9 @@ namespace { CFX_WideString EncodeToCodewords(const CFX_WideString& sb, int32_t startPos) { - wchar_t c1 = sb.GetAt(startPos); - wchar_t c2 = sb.GetAt(startPos + 1); - wchar_t c3 = sb.GetAt(startPos + 2); + wchar_t c1 = sb[startPos]; + wchar_t c2 = sb[startPos + 1]; + wchar_t c3 = sb[startPos + 2]; int32_t v = (1600 * c1) + (40 * c2) + c3 + 1; wchar_t cw[2]; cw[0] = static_cast<wchar_t>(v / 256); diff --git a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp index 405b4f72a1..934d79503c 100644 --- a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp +++ b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp @@ -107,7 +107,7 @@ void CBC_DefaultPlacement::module(int32_t row, col += m_numcols; row += 4 - ((m_numcols + 4) % 8); } - int32_t v = m_codewords.GetAt(pos); + int32_t v = m_codewords[pos]; v &= 1 << (8 - bit); setBit(col, row, v != 0); } diff --git a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp index c7d6b317c1..7407efb47e 100644 --- a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp +++ b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp @@ -38,10 +38,10 @@ CFX_WideString EncodeToCodewords(const CFX_WideString& sb, int32_t startPos) { if (len == 0) return CFX_WideString(); - wchar_t c1 = sb.GetAt(startPos); - wchar_t c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0; - wchar_t c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0; - wchar_t c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0; + wchar_t c1 = sb[startPos]; + wchar_t c2 = len >= 2 ? sb[startPos + 1] : 0; + wchar_t c3 = len >= 3 ? sb[startPos + 2] : 0; + wchar_t c4 = len >= 4 ? sb[startPos + 3] : 0; int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4; constexpr int32_t kBuflen = 3; wchar_t cw[kBuflen]; diff --git a/fxbarcode/datamatrix/BC_EncoderContext.cpp b/fxbarcode/datamatrix/BC_EncoderContext.cpp index 404c07d980..eaf3768f49 100644 --- a/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ b/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -36,8 +36,8 @@ CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString& msg, CFX_WideString sb; FX_STRSIZE c = dststr.GetLength(); for (FX_STRSIZE i = 0; i < c; i++) { - wchar_t ch = static_cast<wchar_t>(dststr.GetAt(i) & 0xff); - if (ch == '?' && dststr.GetAt(i) != '?') { + wchar_t ch = static_cast<wchar_t>(dststr[i] & 0xff); + if (ch == '?' && dststr[i] != '?') { e = BCExceptionCharactersOutsideISO88591Encoding; } sb += ch; @@ -60,10 +60,10 @@ void CBC_EncoderContext::setSkipAtEnd(int32_t count) { m_skipAtEnd = count; } wchar_t CBC_EncoderContext::getCurrentChar() { - return m_msg.GetAt(m_pos); + return m_msg[m_pos]; } wchar_t CBC_EncoderContext::getCurrent() { - return m_msg.GetAt(m_pos); + return m_msg[m_pos]; } void CBC_EncoderContext::writeCodewords(const CFX_WideString& codewords) { diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp index 4071602303..2e84df5c59 100644 --- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -150,7 +150,7 @@ CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, for (int32_t block = 0; block < blockCount; block++) { CFX_WideString temp; for (int32_t d = block; d < symbolInfo->dataCapacity(); d += blockCount) { - temp += (wchar_t)codewords.GetAt(d); + temp += (wchar_t)codewords[d]; } CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e); if (e != BCExceptionNO) @@ -158,7 +158,7 @@ CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, int32_t pos = 0; for (int32_t l = block; l < errorSizes[block] * blockCount; l += blockCount) { - sb.SetAt(symbolInfo->dataCapacity() + l, ecc.GetAt(pos++)); + sb.SetAt(symbolInfo->dataCapacity() + l, ecc[pos++]); } } } @@ -186,7 +186,7 @@ CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, uint16_t* ecc = FX_Alloc(uint16_t, numECWords); memset(ecc, 0, numECWords * sizeof(uint16_t)); for (int32_t l = start; l < start + len; l++) { - uint16_t m = ecc[numECWords - 1] ^ codewords.GetAt(l); + uint16_t m = ecc[numECWords - 1] ^ codewords[l]; for (int32_t k = numECWords - 1; k > 0; k--) { if (m != 0 && FACTORS[table][k] != 0) { ecc[k] = (uint16_t)(ecc[k - 1] ^ diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index 6034173ee4..8b8b413c9b 100644 --- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -174,7 +174,7 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, } return C40_ENCODATION; } - wchar_t c = msg.GetAt(startpos + charsProcessed); + wchar_t c = msg[startpos + charsProcessed]; charsProcessed++; if (isDigit(c)) { charCounts[ASCII_ENCODATION] += 0.5; @@ -253,7 +253,7 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) { int32_t p = startpos + charsProcessed + 1; while (p < msg.GetLength()) { - wchar_t tc = msg.GetAt(p); + wchar_t tc = msg[p]; if (isX12TermSep(tc)) { return X12_ENCODATION; } @@ -280,12 +280,12 @@ int32_t CBC_HighLevelEncoder::determineConsecutiveDigitCount(CFX_WideString msg, int32_t len = msg.GetLength(); int32_t idx = startpos; if (idx < len) { - wchar_t ch = msg.GetAt(idx); + wchar_t ch = msg[idx]; while (isDigit(ch) && idx < len) { count++; idx++; if (idx < len) { - ch = msg.GetAt(idx); + ch = msg[idx]; } } } |