diff options
author | tsepez <tsepez@chromium.org> | 2016-09-13 12:23:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-13 12:23:30 -0700 |
commit | f86ca3884886506c999a3b521078151e7cda0bf9 (patch) | |
tree | 691e3fe357541698159f3ca903a85461e20a43f0 | |
parent | f34518bd1379289659b4c050d140690ba8f8b8aa (diff) | |
download | pdfium-f86ca3884886506c999a3b521078151e7cda0bf9.tar.xz |
Remove more strcmp/memcmp usage.
Review-Url: https://codereview.chromium.org/2340513002
-rw-r--r-- | core/fpdfapi/fpdf_cmaps/cmap_int.h | 3 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/font_int.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 26 | ||||
-rw-r--r-- | fpdfsdk/fpdfppo.cpp | 13 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_ScrollBar.cpp | 20 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_ScrollBar.h | 28 |
7 files changed, 61 insertions, 41 deletions
diff --git a/core/fpdfapi/fpdf_cmaps/cmap_int.h b/core/fpdfapi/fpdf_cmaps/cmap_int.h index 685d6fe4b1..5735432371 100644 --- a/core/fpdfapi/fpdf_cmaps/cmap_int.h +++ b/core/fpdfapi/fpdf_cmaps/cmap_int.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFAPI_FPDF_CMAPS_CMAP_INT_H_ #define CORE_FPDFAPI_FPDF_CMAPS_CMAP_INT_H_ +#include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" struct FXCMAP_CMap { @@ -22,7 +23,7 @@ struct FXCMAP_CMap { int m_UseOffset; }; -void FPDFAPI_FindEmbeddedCMap(const char* name, +void FPDFAPI_FindEmbeddedCMap(const CFX_ByteString& name, int charset, int coding, const FXCMAP_CMap*& pMap); diff --git a/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp b/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp index 1e0250c1af..caf234badb 100644 --- a/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp +++ b/core/fpdfapi/fpdf_cmaps/fpdf_cmaps.cpp @@ -53,7 +53,7 @@ static int compareDWordSingle(const void* p1, const void* p2) { }; // extern "C" -void FPDFAPI_FindEmbeddedCMap(const char* name, +void FPDFAPI_FindEmbeddedCMap(const CFX_ByteString& bsName, int charset, int coding, const FXCMAP_CMap*& pMap) { @@ -64,10 +64,10 @@ void FPDFAPI_FindEmbeddedCMap(const char* name, pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList; for (uint32_t i = 0; i < pFontGlobals->m_EmbeddedCharsets[charset].m_Count; i++) { - if (FXSYS_strcmp(name, pCMaps[i].m_Name)) - continue; - pMap = &pCMaps[i]; - break; + if (bsName == pCMaps[i].m_Name) { + pMap = &pCMaps[i]; + break; + } } } diff --git a/core/fpdfapi/fpdf_font/font_int.h b/core/fpdfapi/fpdf_font/font_int.h index a09bb6bce6..e4689bfd74 100644 --- a/core/fpdfapi/fpdf_font/font_int.h +++ b/core/fpdfapi/fpdf_font/font_int.h @@ -139,7 +139,7 @@ class CPDF_CMap { ~CPDF_CMap(); FX_BOOL LoadPredefined(CPDF_CMapManager* pMgr, - const FX_CHAR* name, + const CFX_ByteString& name, FX_BOOL bPromptCJK); FX_BOOL LoadEmbedded(const uint8_t* pData, uint32_t dwSize); diff --git a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp index d8cada7af3..457f8eec3e 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -315,10 +315,9 @@ CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, } void CPDF_CMapManager::ReloadAll() { - for (const auto& pair : m_CMaps) { - CPDF_CMap* pCMap = pair.second; - pCMap->LoadPredefined(this, pair.first.c_str(), FALSE); - } + for (const auto& pair : m_CMaps) + pair.second->LoadPredefined(this, pair.first, FALSE); + for (size_t i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) { if (CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]) { pMap->Load(this, CIDSetFromSizeT(i), FALSE); @@ -528,12 +527,12 @@ FX_BOOL CPDF_CMap::IsVertWriting() const { } FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, - const FX_CHAR* pName, + const CFX_ByteString& bsName, FX_BOOL bPromptCJK) { - m_PredefinedCMap = pName; + m_PredefinedCMap = bsName; if (m_PredefinedCMap == "Identity-H" || m_PredefinedCMap == "Identity-V") { m_Coding = CIDCODING_CID; - m_bVertical = pName[9] == 'V'; + m_bVertical = bsName[9] == 'V'; m_bLoaded = TRUE; return TRUE; } @@ -564,13 +563,14 @@ FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, } } } - FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap); - if (m_pEmbedMap) { - m_bLoaded = TRUE; - return TRUE; - } - return FALSE; + FPDFAPI_FindEmbeddedCMap(bsName, m_Charset, m_Coding, m_pEmbedMap); + if (!m_pEmbedMap) + return FALSE; + + m_bLoaded = TRUE; + return TRUE; } + FX_BOOL CPDF_CMap::LoadEmbedded(const uint8_t* pData, uint32_t size) { m_pMapping = FX_Alloc(uint16_t, 65536); CPDF_CMapParser parser; diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp index 85dba5e975..3432fb6e6e 100644 --- a/fpdfsdk/fpdfppo.cpp +++ b/fpdfsdk/fpdfppo.cpp @@ -223,17 +223,12 @@ FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, const CFX_ByteString& key = it->first; CPDF_Object* pNextObj = it->second; ++it; - if (!FXSYS_strcmp(key.c_str(), "Parent") || - !FXSYS_strcmp(key.c_str(), "Prev") || - !FXSYS_strcmp(key.c_str(), "First")) { + if (key == "Parent" || key == "Prev" || key == "First") continue; - } - if (pNextObj) { - if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) - pDict->RemoveAt(key); - } else { + if (!pNextObj) return FALSE; - } + if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) + pDict->RemoveAt(key); } break; } diff --git a/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp b/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp index 1789d15764..17f62f58d6 100644 --- a/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp +++ b/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp @@ -818,15 +818,14 @@ void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, } break; case PNM_SETSCROLLINFO: { - if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam) { - if (FXSYS_memcmp(&m_OriginInfo, pInfo, sizeof(PWL_SCROLL_INFO)) != 0) { - m_OriginInfo = *pInfo; - FX_FLOAT fMax = - pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth; - fMax = fMax > 0.0f ? fMax : 0.0f; - SetScrollRange(0, fMax, pInfo->fPlateWidth); - SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep); - } + PWL_SCROLL_INFO* pInfo = reinterpret_cast<PWL_SCROLL_INFO*>(lParam); + if (pInfo && *pInfo != m_OriginInfo) { + m_OriginInfo = *pInfo; + FX_FLOAT fMax = + pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth; + fMax = fMax > 0.0f ? fMax : 0.0f; + SetScrollRange(0, fMax, pInfo->fPlateWidth); + SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep); } } break; case PNM_SETSCROLLPOS: { @@ -1183,13 +1182,12 @@ void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) { void CPWL_ScrollBar::TimerProc() { PWL_SCROLL_PRIVATEDATA sTemp = m_sData; - if (m_bMinOrMax) m_sData.SubSmall(); else m_sData.AddSmall(); - if (FXSYS_memcmp(&m_sData, &sTemp, sizeof(PWL_SCROLL_PRIVATEDATA)) != 0) { + if (sTemp != m_sData) { MovePosButton(TRUE); NotifyScrollWindow(); } diff --git a/fpdfsdk/pdfwindow/PWL_ScrollBar.h b/fpdfsdk/pdfwindow/PWL_ScrollBar.h index c03b20dbbc..ae71472696 100644 --- a/fpdfsdk/pdfwindow/PWL_ScrollBar.h +++ b/fpdfsdk/pdfwindow/PWL_ScrollBar.h @@ -20,6 +20,16 @@ struct PWL_SCROLL_INFO { fPlateWidth(0.0f), fBigStep(0.0f), fSmallStep(0.0f) {} + + bool operator==(const PWL_SCROLL_INFO& that) const { + return fContentMin == that.fContentMin && fContentMax == that.fContentMax && + fPlateWidth == that.fPlateWidth && fBigStep == that.fBigStep && + fSmallStep == that.fSmallStep; + } + bool operator!=(const PWL_SCROLL_INFO& that) const { + return !(*this == that); + } + FX_FLOAT fContentMin; FX_FLOAT fContentMax; FX_FLOAT fPlateWidth; @@ -58,18 +68,34 @@ struct PWL_FLOATRANGE { public: PWL_FLOATRANGE(); PWL_FLOATRANGE(FX_FLOAT min, FX_FLOAT max); + + bool operator==(const PWL_FLOATRANGE& that) const { + return fMin == that.fMin && fMax == that.fMax; + } + bool operator!=(const PWL_FLOATRANGE& that) const { return !(*this == that); } + void Default(); void Set(FX_FLOAT min, FX_FLOAT max); FX_BOOL In(FX_FLOAT x) const; FX_FLOAT GetWidth() const; - FX_FLOAT fMin, fMax; + FX_FLOAT fMin; + FX_FLOAT fMax; }; struct PWL_SCROLL_PRIVATEDATA { public: PWL_SCROLL_PRIVATEDATA(); + bool operator==(const PWL_SCROLL_PRIVATEDATA& that) const { + return ScrollRange == that.ScrollRange && + fClientWidth == that.fClientWidth && fScrollPos == that.fScrollPos && + fBigStep == that.fBigStep && fSmallStep == that.fSmallStep; + } + bool operator!=(const PWL_SCROLL_PRIVATEDATA& that) const { + return !(*this == that); + } + void Default(); void SetScrollRange(FX_FLOAT min, FX_FLOAT max); void SetClientWidth(FX_FLOAT width); |