summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-12-22 13:48:10 -0800
committerLei Zhang <thestig@chromium.org>2015-12-22 13:48:10 -0800
commit1fc92867ca53f0fba4272fbee3814d844f487495 (patch)
tree8c81760b66d1e8da186bddc52d38f350f4e85bf1
parentf6dafc90ec1a0df8d618efc68c0223f0cdd80ffb (diff)
downloadpdfium-1fc92867ca53f0fba4272fbee3814d844f487495.tar.xz
Add ContainsKey() and ContainsValue() and use them where appropriate.
R=ochang@chromium.org Review URL: https://codereview.chromium.org/1540263003 .
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_font/ttgsubtable.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp9
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp20
-rw-r--r--core/src/fpdfdoc/doc_form.cpp13
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp6
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp7
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp5
-rw-r--r--fpdfsdk/src/javascript/util.cpp12
-rw-r--r--third_party/base/stl_util.h15
10 files changed, 49 insertions, 44 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 7b3f8055fb..a3de6f2777 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -13,6 +13,7 @@
#include "core/include/fpdfapi/fpdf_resource.h"
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxge/fx_freetype.h"
+#include "third_party/base/stl_util.h"
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
#include "core/src/fxge/apple/apple_int.h"
@@ -1727,7 +1728,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
rcBBox.top = FXSYS_round(char_rect.top * 1000);
rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000);
- FXSYS_assert(m_CacheMap.find(charcode) == m_CacheMap.end());
+ ASSERT(!pdfium::ContainsKey(m_CacheMap, charcode));
CPDF_Type3Char* pCachedChar = pNewChar.release();
m_CacheMap[charcode] = pCachedChar;
if (pCachedChar->m_pForm->CountObjects() == 0) {
diff --git a/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp b/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp
index 035ea8a0ff..b10aa6952a 100644
--- a/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp
+++ b/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp
@@ -9,6 +9,7 @@
#include "core/include/fxge/fx_freetype.h"
#include "core/include/fxge/fx_ge.h"
#include "third_party/base/nonstd_unique_ptr.h"
+#include "third_party/base/stl_util.h"
CFX_GlyphMap::CFX_GlyphMap() {}
CFX_GlyphMap::~CFX_GlyphMap() {}
@@ -86,7 +87,7 @@ bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum,
k);
if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] ||
FeatureList.FeatureRecord[index].FeatureTag == tag[1]) {
- if (m_featureMap.find(index) == m_featureMap.end()) {
+ if (!pdfium::ContainsKey(m_featureMap, index)) {
m_featureMap[index] = index;
}
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 1322864757..b94a6d91b3 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -7,6 +7,7 @@
#include "core/include/fpdfapi/fpdf_parser.h"
#include "core/include/fxcrt/fx_string.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -284,12 +285,10 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
case PDFOBJ_REFERENCE: {
const CPDF_Reference* pRef = AsReference();
FX_DWORD obj_num = pRef->GetRefObjNum();
- if (bDirect && visited->find(obj_num) == visited->end()) {
+ if (bDirect && !pdfium::ContainsKey(*visited, obj_num)) {
visited->insert(obj_num);
- if (!pRef->GetDirect())
- return nullptr;
-
- return pRef->GetDirect()->CloneInternal(TRUE, visited);
+ auto* pDirect = pRef->GetDirect();
+ return pDirect ? pDirect->CloneInternal(TRUE, visited) : nullptr;
}
return new CPDF_Reference(pRef->m_pObjList, obj_num);
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index d9697000e5..d5a2780980 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -596,7 +596,7 @@ FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) {
return FALSE;
}
// Check for circular references.
- if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) {
+ if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) {
return FALSE;
}
}
@@ -1204,7 +1204,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList,
const int32_t offset = GetStreamFirst(pObjStream);
// Read object numbers from |pObjStream| into a cache.
- if (m_ObjCache.find(pObjStream) == m_ObjCache.end()) {
+ if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) {
for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) {
FX_DWORD thisnum = syntax.GetDirectNum();
FX_DWORD thisoff = syntax.GetDirectNum();
@@ -1634,7 +1634,7 @@ FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) {
return FALSE;
}
// Check for circular references.
- if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) {
+ if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) {
return FALSE;
}
}
@@ -2766,7 +2766,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
CPDF_PageNode* pPageNode,
IFX_DownloadHints* pHints);
FX_BOOL CheckPageCount(IFX_DownloadHints* pHints);
- FX_BOOL IsFirstCheck(int iPage);
+ bool IsFirstCheck(int iPage);
void ResetFirstCheck(int iPage);
FX_BOOL IsDataAvail(FX_FILESIZE offset,
FX_DWORD size,
@@ -3349,12 +3349,8 @@ FX_BOOL CPDF_DataAvail::PreparePageItem() {
m_docStatus = PDF_DATAAVAIL_PAGETREE;
return TRUE;
}
-FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) {
- if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end())
- return FALSE;
-
- m_pageMapCheckState.insert(iPage);
- return TRUE;
+bool CPDF_DataAvail::IsFirstCheck(int iPage) {
+ return m_pageMapCheckState.insert(iPage).second;
}
void CPDF_DataAvail::ResetFirstCheck(int iPage) {
m_pageMapCheckState.erase(iPage);
@@ -4381,9 +4377,9 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
m_objs_array.RemoveAll();
m_objnum_array.RemoveAll();
}
- if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) {
+ if (pdfium::ContainsKey(m_pagesLoadState, iPage))
return DataAvailable;
- }
+
if (m_bLinearized) {
if ((FX_DWORD)iPage == m_dwFirstPageNo) {
m_pagesLoadState.insert(iPage);
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 9f949cc965..c49f042b32 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -6,6 +6,7 @@
#include "core/include/fpdfdoc/fpdf_doc.h"
#include "doc_utils.h"
+#include "third_party/base/stl_util.h"
const int nMaxRecursion = 32;
@@ -831,8 +832,7 @@ bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
if (!pField)
continue;
- auto it = std::find(fields.begin(), fields.end(), pField);
- if (bIncludeOrExclude == (it != fields.end()))
+ if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField))
pField->ResetField(bNotify);
}
if (bNotify && m_pFormNotify)
@@ -1004,10 +1004,8 @@ CPDF_FormField* CPDF_InterForm::CheckRequiredFields(
continue;
bool bFind = true;
- if (fields) {
- auto it = std::find(fields->begin(), fields->end(), pField);
- bFind = (it != fields->end());
- }
+ if (fields)
+ bFind = pdfium::ContainsValue(*fields, pField);
if (bIncludeOrExclude == bFind) {
CPDF_Dictionary* pFieldDict = pField->m_pDict;
if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) {
@@ -1060,8 +1058,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(
if (dwFlags & 0x04)
continue;
- auto it = std::find(fields.begin(), fields.end(), pField);
- if (bIncludeOrExclude == (it != fields.end())) {
+ if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) {
if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty())
continue;
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp
index d169081b5f..1101da2344 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -9,7 +9,7 @@
#include "core/include/fxge/fx_freetype.h"
#include "core/include/fxge/fx_ge.h"
#include "core/src/fxge/fontdata/chromefontdata/chromefontdata.h"
-#include "text_int.h"
+#include "core/src/fxge/ge/text_int.h"
#include "third_party/base/stl_util.h"
#define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1])
@@ -1347,9 +1347,9 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path,
if (style != "Regular") {
facename += " " + style;
}
- if (m_FontList.find(facename) != m_FontList.end()) {
+ if (pdfium::ContainsKey(m_FontList, facename))
return;
- }
+
CFX_FontFaceInfo* pInfo =
new CFX_FontFaceInfo(path, facename, tables, offset, filesize);
CFX_ByteString os2 = FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32);
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index e01fe89610..03edd83891 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -13,6 +13,7 @@
#include "fpdfsdk/include/javascript/IJavaScript.h"
#include "public/fpdf_ext.h"
#include "third_party/base/nonstd_unique_ptr.h"
+#include "third_party/base/stl_util.h"
#if _FX_OS_ == _FX_ANDROID_
#include "time.h"
@@ -689,9 +690,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX,
void CPDFSDK_PageView::KillFocusAnnotIfNeeded() {
// if there is a focused annot on the page, we should kill the focus first.
if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) {
- auto it =
- std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), focusedAnnot);
- if (it != m_fxAnnotArray.end())
+ if (pdfium::ContainsValue(m_fxAnnotArray, focusedAnnot))
KillFocusAnnot();
}
}
@@ -911,7 +910,7 @@ bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const {
return false;
const auto& annots = m_pAnnotList->All();
- return std::find(annots.begin(), annots.end(), p) != annots.end();
+ return pdfium::ContainsValue(annots, p);
}
CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index f52e23a094..b08823f6ed 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -26,6 +26,7 @@
#include "global.h"
#include "report.h"
#include "util.h"
+#include "third_party/base/stl_util.h"
// static
void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
@@ -206,11 +207,11 @@ v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
}
void CJS_Runtime::AddObserver(Observer* observer) {
- ASSERT(m_observers.find(observer) == m_observers.end());
+ ASSERT(!pdfium::ContainsKey(m_observers, observer));
m_observers.insert(observer);
}
void CJS_Runtime::RemoveObserver(Observer* observer) {
- ASSERT(m_observers.find(observer) != m_observers.end());
+ ASSERT(pdfium::ContainsKey(m_observers, observer));
m_observers.erase(observer);
}
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index cb9c9b2231..a14e81c203 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -468,17 +468,13 @@ void util::printx(const std::string& cFormat,
case '\\':
break;
case '>': {
- for (std::string::iterator it = cSource.begin(); it != cSource.end();
- it++) {
- *it = toupper(*it);
- }
+ for (char& c : cSource)
+ c = toupper(c);
break;
}
case '<': {
- for (std::string::iterator it = cSource.begin(); it != cSource.end();
- it++) {
- *it = tolower(*it);
- }
+ for (char& c : cSource)
+ c = tolower(c);
break;
}
case '=':
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h
index fcbe5882a2..50e9341569 100644
--- a/third_party/base/stl_util.h
+++ b/third_party/base/stl_util.h
@@ -22,6 +22,21 @@ inline const T* vector_as_array(const std::vector<T>* v) {
return v->empty() ? nullptr : &*v->begin();
}
+// Test to see if a set, map, hash_set or hash_map contains a particular key.
+// Returns true if the key is in the collection.
+template <typename Collection, typename Key>
+bool ContainsKey(const Collection& collection, const Key& key) {
+ return collection.find(key) != collection.end();
+}
+
+// Test to see if a collection like a vector contains a particular value.
+// Returns true if the value is in the collection.
+template <typename Collection, typename Value>
+bool ContainsValue(const Collection& collection, const Value& value) {
+ return std::find(collection.begin(), collection.end(), value) !=
+ collection.end();
+}
+
} // namespace pdfium
#endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_