Initialize more member variables in the header.
Do this for CWeightTable and CPDF_StructKid. For CPDF_StructKid, also
change one of its enums to have "kFoo" for enum values instead of "Foo",
per style guide, and give them enum a name. Pack the CPDF_StructKid
members more tightly as well.
Change-Id: I8fd9da53021e346ea93a3658b9cbebc67a6205f0
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63733
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp
index 50fa83d..40477b4 100644
--- a/core/fpdfdoc/cpdf_structelement.cpp
+++ b/core/fpdfdoc/cpdf_structelement.cpp
@@ -32,11 +32,7 @@
} // namespace
-CPDF_StructKid::CPDF_StructKid()
- : m_Type(Invalid),
- m_PageObjNum(0),
- m_RefObjNum(0),
- m_ContentId(0) {}
+CPDF_StructKid::CPDF_StructKid() = default;
CPDF_StructKid::CPDF_StructKid(const CPDF_StructKid& that) = default;
@@ -67,7 +63,7 @@
}
CPDF_StructElement* CPDF_StructElement::GetKidIfElement(size_t index) const {
- return m_Kids[index].m_Type == CPDF_StructKid::Element
+ return m_Kids[index].m_Type == CPDF_StructKid::kElement
? m_Kids[index].m_pElement.Get()
: nullptr;
}
@@ -99,7 +95,7 @@
void CPDF_StructElement::LoadKid(uint32_t PageObjNum,
const CPDF_Object* pKidObj,
CPDF_StructKid* pKid) {
- pKid->m_Type = CPDF_StructKid::Invalid;
+ pKid->m_Type = CPDF_StructKid::kInvalid;
if (!pKidObj)
return;
@@ -107,7 +103,7 @@
if (m_pTree->GetPage()->GetObjNum() != PageObjNum)
return;
- pKid->m_Type = CPDF_StructKid::PageContent;
+ pKid->m_Type = CPDF_StructKid::kPageContent;
pKid->m_ContentId = pKidObj->GetInteger();
pKid->m_PageObjNum = PageObjNum;
return;
@@ -126,7 +122,7 @@
}
if (type == "MCR") {
- pKid->m_Type = CPDF_StructKid::StreamContent;
+ pKid->m_Type = CPDF_StructKid::kStreamContent;
const CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Stm"));
pKid->m_RefObjNum = pRef ? pRef->GetRefObjNum() : 0;
pKid->m_PageObjNum = PageObjNum;
@@ -135,14 +131,14 @@
}
if (type == "OBJR") {
- pKid->m_Type = CPDF_StructKid::Object;
+ pKid->m_Type = CPDF_StructKid::kObject;
const CPDF_Reference* pObj = ToReference(pKidDict->GetObjectFor("Obj"));
pKid->m_RefObjNum = pObj ? pObj->GetRefObjNum() : 0;
pKid->m_PageObjNum = PageObjNum;
return;
}
- pKid->m_Type = CPDF_StructKid::Element;
+ pKid->m_Type = CPDF_StructKid::kElement;
pKid->m_pDict.Reset(pKidDict);
pKid->m_pElement = nullptr;
}
diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h
index ae40a40..54042a9 100644
--- a/core/fpdfdoc/cpdf_structelement.h
+++ b/core/fpdfdoc/cpdf_structelement.h
@@ -20,17 +20,18 @@
class CPDF_StructKid {
public:
+ enum Type { kInvalid, kElement, kPageContent, kStreamContent, kObject };
+
CPDF_StructKid();
CPDF_StructKid(const CPDF_StructKid& that);
~CPDF_StructKid();
- enum { Invalid, Element, PageContent, StreamContent, Object } m_Type;
-
+ Type m_Type = kInvalid;
+ uint32_t m_PageObjNum = 0; // For {PageContent, StreamContent, Object} types.
+ uint32_t m_RefObjNum = 0; // For {StreamContent, Object} types.
+ uint32_t m_ContentId = 0; // For {PageContent, StreamContent} types.
RetainPtr<CPDF_StructElement> m_pElement; // For Element.
RetainPtr<const CPDF_Dictionary> m_pDict; // For Element.
- uint32_t m_PageObjNum; // For PageContent, StreamContent, Object.
- uint32_t m_RefObjNum; // For StreamContent, Object.
- uint32_t m_ContentId; // For PageContent, StreamContent.
};
class CPDF_StructElement final : public Retainable {
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index 25eb9cd..8fd43e2 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -107,7 +107,7 @@
AddPageNode(pParent, map, nLevel + 1);
bool bSave = false;
for (CPDF_StructKid& kid : *pParentElement->GetKids()) {
- if (kid.m_Type == CPDF_StructKid::Element && kid.m_pDict == pDict) {
+ if (kid.m_Type == CPDF_StructKid::kElement && kid.m_pDict == pDict) {
kid.m_pElement = pElement;
bSave = true;
}
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 95f2c83..827a2c9 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -18,7 +18,7 @@
namespace {
-const int kMaxDestValue = 16711680;
+constexpr int kMaxDestValue = 16711680;
int GetPitchRoundUpTo4Bytes(int bits_per_pixel) {
return (bits_per_pixel + 31) / 32 * 4;
@@ -26,12 +26,9 @@
} // namespace
-CStretchEngine::CWeightTable::CWeightTable()
- : m_DestMin(0),
- m_ItemSize(0),
- m_dwWeightTablesSize(0) {}
+CStretchEngine::CWeightTable::CWeightTable() = default;
-CStretchEngine::CWeightTable::~CWeightTable() {}
+CStretchEngine::CWeightTable::~CWeightTable() = default;
size_t CStretchEngine::CWeightTable::GetPixelWeightSize() const {
return m_ItemSize / sizeof(int) - 2;
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index c2aaca6..1792963 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -58,10 +58,10 @@
size_t GetPixelWeightSize() const;
private:
- int m_DestMin;
- int m_ItemSize;
+ int m_DestMin = 0;
+ int m_ItemSize = 0;
+ size_t m_dwWeightTablesSize = 0;
std::vector<uint8_t> m_WeightTables;
- size_t m_dwWeightTablesSize;
};
enum class State : uint8_t { kInitial, kHorizontal, kVertical };