From 007e6c0f9559412788b903bcb6a7601e220c3be8 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 26 Feb 2016 14:31:56 -0800 Subject: Remove some FX_BOOLs Grepping for FX_BOOL and |==| on the same line gives a very strong clue that the expression won't be out of range of the |bool| type iteself. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1736323003 . --- core/include/fpdfapi/fpdf_objects.h | 2 +- core/include/fpdfapi/fpdf_page.h | 2 +- core/include/fpdfdoc/fpdf_vt.h | 7 ++----- core/include/fxcrt/fx_basic.h | 10 ++-------- core/include/fxcrt/fx_coordinates.h | 9 ++++----- core/include/fxge/fx_dib.h | 11 ++++------- core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 4 ++-- core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp | 16 ++++++++-------- core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp | 6 +++--- core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 20 ++++++++++---------- core/src/fpdfdoc/doc_annot.cpp | 6 +++--- core/src/fxcodec/codec/fx_codec_progress.cpp | 2 +- core/src/fxcrt/fx_arabic.cpp | 2 +- core/src/fxge/android/fpf_skiafontmgr.cpp | 4 ++-- core/src/fxge/dib/fx_dib_composite.cpp | 2 +- core/src/fxge/ge/fx_ge_text.cpp | 4 ++-- core/src/fxge/win32/fx_win32_device.cpp | 3 +-- 17 files changed, 48 insertions(+), 62 deletions(-) (limited to 'core') diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index 129eebfcfc..5791b7e6b3 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -445,7 +445,7 @@ class CPDF_Stream : public CPDF_Object { uint8_t* pBuf, FX_DWORD buf_size) const; - FX_BOOL IsMemoryBased() const { return m_GenNum == kMemoryBasedGenNum; } + bool IsMemoryBased() const { return m_GenNum == kMemoryBasedGenNum; } protected: static const FX_DWORD kMemoryBasedGenNum = (FX_DWORD)-1; diff --git a/core/include/fpdfapi/fpdf_page.h b/core/include/fpdfapi/fpdf_page.h index 3d98e34578..973a28030f 100644 --- a/core/include/fpdfapi/fpdf_page.h +++ b/core/include/fpdfapi/fpdf_page.h @@ -39,7 +39,7 @@ class CPDF_PageObjectHolder { CPDF_PageObjectHolder(); void ContinueParse(IFX_Pause* pPause); - FX_BOOL IsParsed() const { return m_ParseState == CONTENT_PARSED; } + bool IsParsed() const { return m_ParseState == CONTENT_PARSED; } CPDF_PageObjectList* GetPageObjectList() { return &m_PageObjectList; } const CPDF_PageObjectList* GetPageObjectList() const { diff --git a/core/include/fpdfdoc/fpdf_vt.h b/core/include/fpdfdoc/fpdf_vt.h index b2e64cd2ed..8a2e7e93aa 100644 --- a/core/include/fpdfdoc/fpdf_vt.h +++ b/core/include/fpdfdoc/fpdf_vt.h @@ -32,15 +32,12 @@ struct CPVT_WordPlace { void Default() { nSecIndex = nLineIndex = nWordIndex = -1; } - FX_BOOL operator==(const CPVT_WordPlace& wp) const { + bool operator==(const CPVT_WordPlace& wp) const { return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex && wp.nWordIndex == nWordIndex; } - FX_BOOL operator!=(const CPVT_WordPlace& wp) const { - return wp.nSecIndex != nSecIndex || wp.nLineIndex != nLineIndex || - wp.nWordIndex != nWordIndex; - } + FX_BOOL operator!=(const CPVT_WordPlace& wp) const { return !(*this == wp); } inline int32_t WordCmp(const CPVT_WordPlace& wp) const { if (nSecIndex > wp.nSecIndex) { diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h index 01bb6e2c76..6e092dd540 100644 --- a/core/include/fxcrt/fx_basic.h +++ b/core/include/fxcrt/fx_basic.h @@ -601,20 +601,16 @@ class CFX_MapPtrToPtr { protected: struct CAssoc { CAssoc* pNext; - void* key; - void* value; }; public: CFX_MapPtrToPtr(int nBlockSize = 10); - ~CFX_MapPtrToPtr(); int GetCount() const { return m_nCount; } - - FX_BOOL IsEmpty() const { return m_nCount == 0; } + bool IsEmpty() const { return m_nCount == 0; } FX_BOOL Lookup(void* key, void*& rValue) const; @@ -961,9 +957,7 @@ class CFX_CountRef { m_pObject = NULL; } - FX_BOOL operator==(const Ref& ref) const { - return m_pObject == ref.m_pObject; - } + bool operator==(const Ref& ref) const { return m_pObject == ref.m_pObject; } protected: CountedObj* m_pObject; diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h index 30770309a0..c6bf230014 100644 --- a/core/include/fxcrt/fx_coordinates.h +++ b/core/include/fxcrt/fx_coordinates.h @@ -333,13 +333,12 @@ class CFX_RTemplate { rect.Intersect(*this); return !rect.IsEmpty(fEpsilon); } - friend FX_BOOL operator==(const FXT_RECT& rc1, const FXT_RECT& rc2) { + friend bool operator==(const FXT_RECT& rc1, const FXT_RECT& rc2) { return rc1.left == rc2.left && rc1.top == rc2.top && rc1.width == rc2.width && rc1.height == rc2.height; } - friend FX_BOOL operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { - return rc1.left != rc2.left || rc1.top != rc2.top || - rc1.width != rc2.width || rc1.height != rc2.height; + friend bool operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { + return !(rc1 == rc2); } baseType left, top; baseType width, height; @@ -385,7 +384,7 @@ struct FX_RECT { void Union(const FX_RECT& other_rect); - FX_BOOL operator==(const FX_RECT& src) const { + bool operator==(const FX_RECT& src) const { return left == src.left && right == src.right && top == src.top && bottom == src.bottom; } diff --git a/core/include/fxge/fx_dib.h b/core/include/fxge/fx_dib.h index 3043e7547c..e39bad2b87 100644 --- a/core/include/fxge/fx_dib.h +++ b/core/include/fxge/fx_dib.h @@ -199,13 +199,10 @@ class CFX_DIBSource { // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format, // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and // IsOpaqueImage() below should never be able to return TRUE. - FX_BOOL IsAlphaMask() const { return m_AlphaFlag == 1; } - - FX_BOOL HasAlpha() const { return !!(m_AlphaFlag & 2); } - - FX_BOOL IsOpaqueImage() const { return !(m_AlphaFlag & 3); } - - FX_BOOL IsCmykImage() const { return !!(m_AlphaFlag & 4); } + bool IsAlphaMask() const { return m_AlphaFlag == 1; } + bool HasAlpha() const { return !!(m_AlphaFlag & 2); } + bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); } + bool IsCmykImage() const { return !!(m_AlphaFlag & 4); } int GetPaletteSize() const { return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index f103786350..878dc2ab2a 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -1270,7 +1270,7 @@ int32_t CPDF_Creator::WriteOldIndirectObject(FX_DWORD objnum) { FX_BOOL bExistInMap = pdfium::ContainsKey(m_pDocument->m_IndirectObjs, objnum); const uint8_t object_type = m_pParser->GetObjectType(objnum); - FX_BOOL bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream; + bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream; if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap || bObjStm) { CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); @@ -1547,7 +1547,7 @@ int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) { m_pParser->GetLastXRefOffset() == 0) { InitOldObjNumOffsets(); FX_DWORD dwEnd = m_pParser->GetLastObjNum(); - FX_BOOL bObjStm = (m_dwFlags & FPDFCREATE_OBJECTSTREAM) != 0; + bool bObjStm = (m_dwFlags & FPDFCREATE_OBJECTSTREAM) != 0; for (FX_DWORD objnum = 0; objnum <= dwEnd; objnum++) { if (m_pParser->IsObjectFreeOrNull(objnum)) continue; diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp index 3595c99428..bcac9d87d4 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp @@ -263,10 +263,10 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT) { flags |= PDFFONT_SCRIPT; } - FX_BOOL bCJK = pLogFont->lfCharSet == CHINESEBIG5_CHARSET || - pLogFont->lfCharSet == GB2312_CHARSET || - pLogFont->lfCharSet == HANGEUL_CHARSET || - pLogFont->lfCharSet == SHIFTJIS_CHARSET; + bool bCJK = pLogFont->lfCharSet == CHINESEBIG5_CHARSET || + pLogFont->lfCharSet == GB2312_CHARSET || + pLogFont->lfCharSet == HANGEUL_CHARSET || + pLogFont->lfCharSet == SHIFTJIS_CHARSET; CFX_ByteString basefont; if (bTranslateName && bCJK) { basefont = _FPDF_GetPSNameFromTT(hDC); @@ -828,10 +828,10 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { if (!pFont) { return NULL; } - FX_BOOL bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || - charset == FXFONT_GB2312_CHARSET || - charset == FXFONT_HANGEUL_CHARSET || - charset == FXFONT_SHIFTJIS_CHARSET; + bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || + charset == FXFONT_GB2312_CHARSET || + charset == FXFONT_HANGEUL_CHARSET || + charset == FXFONT_SHIFTJIS_CHARSET; CFX_ByteString basefont = pFont->GetFamilyName(); basefont.Replace(" ", ""); int flags = 0; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp index e6106441fe..d56e65c084 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp @@ -271,9 +271,9 @@ CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, return CFX_FloatRect(0, 0, 0, 0); CFX_FloatRect rect; - FX_BOOL bStarted = FALSE; - FX_BOOL bGouraud = type == kFreeFormGouraudTriangleMeshShading || - type == kLatticeFormGouraudTriangleMeshShading; + bool bStarted = false; + bool bGouraud = type == kFreeFormGouraudTriangleMeshShading || + type == kLatticeFormGouraudTriangleMeshShading; int point_count = kSingleCoordinatePair; if (type == kTensorProductPatchMeshShading) diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index cc9a998e57..5998a9236c 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -723,18 +723,18 @@ struct CPDF_PatchDrawer { } }; -FX_BOOL _CheckCoonTensorPara(const CPDF_MeshStream& stream) { - FX_BOOL bCoorBits = (stream.m_nCoordBits == 1 || stream.m_nCoordBits == 2 || - stream.m_nCoordBits == 4 || stream.m_nCoordBits == 8 || - stream.m_nCoordBits == 12 || stream.m_nCoordBits == 16 || - stream.m_nCoordBits == 24 || stream.m_nCoordBits == 32); +bool _CheckCoonTensorPara(const CPDF_MeshStream& stream) { + bool bCoorBits = (stream.m_nCoordBits == 1 || stream.m_nCoordBits == 2 || + stream.m_nCoordBits == 4 || stream.m_nCoordBits == 8 || + stream.m_nCoordBits == 12 || stream.m_nCoordBits == 16 || + stream.m_nCoordBits == 24 || stream.m_nCoordBits == 32); - FX_BOOL bCompBits = (stream.m_nCompBits == 1 || stream.m_nCompBits == 2 || - stream.m_nCompBits == 4 || stream.m_nCompBits == 8 || - stream.m_nCompBits == 12 || stream.m_nCompBits == 16); + bool bCompBits = (stream.m_nCompBits == 1 || stream.m_nCompBits == 2 || + stream.m_nCompBits == 4 || stream.m_nCompBits == 8 || + stream.m_nCompBits == 12 || stream.m_nCompBits == 16); - FX_BOOL bFlagBits = (stream.m_nFlagBits == 2 || stream.m_nFlagBits == 4 || - stream.m_nFlagBits == 8); + bool bFlagBits = (stream.m_nFlagBits == 2 || stream.m_nFlagBits == 4 || + stream.m_nFlagBits == 8); return bCoorBits && bCompBits && bFlagBits; } diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp index dcd21be66e..09b6e8d673 100644 --- a/core/src/fpdfdoc/doc_annot.cpp +++ b/core/src/fpdfdoc/doc_annot.cpp @@ -55,7 +55,7 @@ void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, CPDF_RenderOptions* pOptions, FX_RECT* clip_rect) { for (CPDF_Annot* pAnnot : m_AnnotList) { - FX_BOOL bWidget = pAnnot->GetSubType() == "Widget"; + bool bWidget = pAnnot->GetSubType() == "Widget"; if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) continue; @@ -255,8 +255,8 @@ void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, if (annot_flags & ANNOTFLAG_HIDDEN) { return; } - FX_BOOL bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || - (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); + bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || + (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { return; } diff --git a/core/src/fxcodec/codec/fx_codec_progress.cpp b/core/src/fxcodec/codec/fx_codec_progress.cpp index fbbfaaf0fa..5d8502a87a 100644 --- a/core/src/fxcodec/codec/fx_codec_progress.cpp +++ b/core/src/fxcodec/codec/fx_codec_progress.cpp @@ -710,7 +710,7 @@ void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule, pal_index = pCodec->m_GifTransIndex; } FXSYS_memset(pCodec->m_pDecodeBuf, pal_index, pCodec->m_SrcWidth); - FX_BOOL bLastPass = (row_num % 2) == 1; + bool bLastPass = (row_num % 2) == 1; int32_t line = row_num + pCodec->m_GifFrameRect.top; int32_t left = pCodec->m_GifFrameRect.left; FXSYS_memcpy(pCodec->m_pDecodeBuf + left, row_buf, img_width); diff --git a/core/src/fxcrt/fx_arabic.cpp b/core/src/fxcrt/fx_arabic.cpp index 953e74ca76..e611be0c52 100644 --- a/core/src/fxcrt/fx_arabic.cpp +++ b/core/src/fxcrt/fx_arabic.cpp @@ -276,7 +276,7 @@ FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, FX_CHARTYPE eNext; FX_WCHAR wNext; ParseChar(next, wNext, eNext); - FX_BOOL bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644); + bool bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644); if (ePrev < FX_CHARTYPE_ArabicAlef) { if (bAlef) { return FX_GetArabicFromAlefTable(wNext); diff --git a/core/src/fxge/android/fpf_skiafontmgr.cpp b/core/src/fxge/android/fpf_skiafontmgr.cpp index 2d4a2c726b..b37343b9e5 100644 --- a/core/src/fxge/android/fpf_skiafontmgr.cpp +++ b/core/src/fxge/android/fpf_skiafontmgr.cpp @@ -280,7 +280,7 @@ IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, if (dwFaceName == dwSysFontName) { nFind += FPF_SKIAMATCHWEIGHT_NAME1; } - FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); + bool bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) { nFind += FPF_SKIAMATCHWEIGHT_1; } @@ -299,7 +299,7 @@ IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, } if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) { nFind += FPF_SKIAMATCHWEIGHT_NAME2; - bMatchedName = TRUE; + bMatchedName = true; } if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) { if (nFind > nMax && bMatchedName) { diff --git a/core/src/fxge/dib/fx_dib_composite.cpp b/core/src/fxge/dib/fx_dib_composite.cpp index 6068dffe75..8bf36e523a 100644 --- a/core/src/fxge/dib/fx_dib_composite.cpp +++ b/core/src/fxge/dib/fx_dib_composite.cpp @@ -4907,7 +4907,7 @@ FX_BOOL CFX_DIBitmap::CompositeRect(int left, } int Bpp = m_bpp / 8; FX_BOOL bAlpha = HasAlpha(); - FX_BOOL bArgb = GetFormat() == FXDIB_Argb; + bool bArgb = GetFormat() == FXDIB_Argb; if (src_alpha == 255) { for (int row = rect.top; row < rect.bottom; row++) { uint8_t* dest_scan = m_pBuffer + row * m_Pitch + rect.left * Bpp; diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp index ae426b093c..8d54363d14 100644 --- a/core/src/fxge/ge/fx_ge_text.cpp +++ b/core/src/fxge/ge/fx_ge_text.cpp @@ -1173,7 +1173,7 @@ CFX_FontCache::~CFX_FontCache() { CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { FXFT_Face internal_face = pFont->GetFace(); - const FX_BOOL bExternal = internal_face == nullptr; + const bool bExternal = !internal_face; FXFT_Face face = bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; @@ -1194,7 +1194,7 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { FXFT_Face internal_face = pFont->GetFace(); - const FX_BOOL bExternal = internal_face == nullptr; + const bool bExternal = !internal_face; FXFT_Face face = bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; diff --git a/core/src/fxge/win32/fx_win32_device.cpp b/core/src/fxge/win32/fx_win32_device.cpp index 58f8769ac7..e9fee082b9 100644 --- a/core/src/fxge/win32/fx_win32_device.cpp +++ b/core/src/fxge/win32/fx_win32_device.cpp @@ -1103,8 +1103,7 @@ FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource, int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); - FX_BOOL bGDI = pSource->GetBPP() == 1 && alpha == 255; - if (!bGDI) { + if (pSource->GetBPP() != 1 || alpha != 255) { CFX_DIBitmap background; if (!background.Create(width, height, FXDIB_Rgb32) || !GetDIBits(&background, left, top, NULL) || -- cgit v1.2.3