summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-15 10:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 15:03:10 +0000
commit8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch)
tree82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /core/fpdfapi
parent171cb27a720036c48ae3a6176084e880742af0a9 (diff)
downloadpdfium-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 'core/fpdfapi')
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp6
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser.cpp25
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap.cpp4
-rw-r--r--core/fpdfapi/render/cpdf_charposlist.cpp2
5 files changed, 19 insertions, 20 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 8cb59de739..9a2261caa9 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -627,7 +627,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
if (uni_str.IsEmpty())
return cid;
- unicode = uni_str.GetAt(0);
+ unicode = uni_str[0];
#endif
} else {
if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded())
@@ -637,7 +637,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
if (unicode == 0) {
CFX_WideString unicode_str = UnicodeFromCharCode(charcode);
if (!unicode_str.IsEmpty())
- unicode = unicode_str.GetAt(0);
+ unicode = unicode_str[0];
}
}
FXFT_Face face = m_Font.GetFace();
@@ -735,7 +735,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
if (unicode_str.IsEmpty())
return -1;
- charcode = unicode_str.GetAt(0);
+ charcode = unicode_str[0];
}
return GetGlyphIndex(charcode, pVertGlyph);
}
diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp
index cbf693966e..272f8deb34 100644
--- a/core/fpdfapi/font/cpdf_cmapparser.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser.cpp
@@ -121,7 +121,7 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
}
m_Status = 0;
} else {
- if (word.GetLength() == 0 || word.GetAt(0) != '<') {
+ if (word.GetLength() == 0 || word[0] != '<') {
return;
}
if (m_CodeSeq % 2) {
@@ -140,18 +140,17 @@ uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
if (word.IsEmpty())
return 0;
pdfium::base::CheckedNumeric<uint32_t> num = 0;
- if (word.GetAt(0) == '<') {
- for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) {
- num = num * 16 + FXSYS_HexCharToInt(word.GetAt(i));
+ if (word[0] == '<') {
+ for (int i = 1; i < word.GetLength() && std::isxdigit(word[i]); ++i) {
+ num = num * 16 + FXSYS_HexCharToInt(word[i]);
if (!num.IsValid())
return 0;
}
return num.ValueOrDie();
}
- for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) {
- num =
- num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word.GetAt(i)));
+ for (int i = 0; i < word.GetLength() && std::isdigit(word[i]); ++i) {
+ num = num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word[i]));
if (!num.IsValid())
return 0;
}
@@ -162,12 +161,12 @@ uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
const CFX_ByteStringC& first,
const CFX_ByteStringC& second) {
- if (first.GetLength() == 0 || first.GetAt(0) != '<')
+ if (first.GetLength() == 0 || first[0] != '<')
return false;
int i;
for (i = 1; i < first.GetLength(); ++i) {
- if (first.GetAt(i) == '>') {
+ if (first[i] == '>') {
break;
}
}
@@ -176,8 +175,8 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
return false;
for (i = 0; i < range.m_CharSize; ++i) {
- uint8_t digit1 = first.GetAt(i * 2 + 1);
- uint8_t digit2 = first.GetAt(i * 2 + 2);
+ uint8_t digit1 = first[i * 2 + 1];
+ uint8_t digit2 = first[i * 2 + 2];
range.m_Lower[i] =
FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2);
}
@@ -185,10 +184,10 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
uint32_t size = second.GetLength();
for (i = 0; i < range.m_CharSize; ++i) {
uint8_t digit1 = ((uint32_t)i * 2 + 1 < size)
- ? second.GetAt((FX_STRSIZE)i * 2 + 1)
+ ? second[static_cast<FX_STRSIZE>(i * 2 + 1)]
: '0';
uint8_t digit2 = ((uint32_t)i * 2 + 2 < size)
- ? second.GetAt((FX_STRSIZE)i * 2 + 2)
+ ? second[static_cast<FX_STRSIZE>(i * 2 + 2)]
: '0';
range.m_Upper[i] =
FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2);
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 82f9be3361..0fd8b45326 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -467,7 +467,7 @@ int CPDF_Font::FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode) {
return -1;
CFX_WideString str = UnicodeFromCharCode(charcode);
- uint32_t unicode = !str.IsEmpty() ? str.GetAt(0) : charcode;
+ uint32_t unicode = !str.IsEmpty() ? str[0] : charcode;
int glyph =
FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), unicode);
if (glyph == 0)
diff --git a/core/fpdfapi/font/cpdf_tounicodemap.cpp b/core/fpdfapi/font/cpdf_tounicodemap.cpp
index 30bf0317ee..9076f4a737 100644
--- a/core/fpdfapi/font/cpdf_tounicodemap.cpp
+++ b/core/fpdfapi/font/cpdf_tounicodemap.cpp
@@ -147,7 +147,7 @@ void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
continue;
}
if (len == 1) {
- m_Map[srccode] = destcode.GetAt(0);
+ m_Map[srccode] = destcode[0];
} else {
m_Map[srccode] = GetUnicode();
m_MultiCharBuf.AppendChar(destcode.GetLength());
@@ -178,7 +178,7 @@ void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
continue;
}
if (len == 1) {
- m_Map[code] = destcode.GetAt(0);
+ m_Map[code] = destcode[0];
} else {
m_Map[code] = GetUnicode();
m_MultiCharBuf.AppendChar(destcode.GetLength());
diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp
index a87fc3334e..f5882d9944 100644
--- a/core/fpdfapi/render/cpdf_charposlist.cpp
+++ b/core/fpdfapi/render/cpdf_charposlist.cpp
@@ -38,7 +38,7 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes,
if (pCIDFont)
charpos.m_bFontStyle = true;
CFX_WideString unicode = pFont->UnicodeFromCharCode(CharCode);
- charpos.m_Unicode = !unicode.IsEmpty() ? unicode.GetAt(0) : CharCode;
+ charpos.m_Unicode = !unicode.IsEmpty() ? unicode[0] : CharCode;
charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert);
uint32_t GlyphID = charpos.m_GlyphIndex;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_