Use more variables to make code shorter.
clang-format likes to write:
result = FooFunc()
->BarFunc()
->QuxFunc();
but it is shorter to write:
auto value = FooFunc()->BarFunc();
result = value->QuxFunc();
Change-Id: Ic7be363a058865e955a728875af207b5177c5f76
Reviewed-on: https://pdfium-review.googlesource.com/c/46730
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/parser/cxfa_caption.cpp b/xfa/fxfa/parser/cxfa_caption.cpp
index 5b27b58..8d6b89e 100644
--- a/xfa/fxfa/parser/cxfa_caption.cpp
+++ b/xfa/fxfa/parser/cxfa_caption.cpp
@@ -46,23 +46,18 @@
CXFA_Caption::~CXFA_Caption() = default;
bool CXFA_Caption::IsVisible() {
- return JSObject()
- ->TryEnum(XFA_Attribute::Presence, true)
- .value_or(XFA_AttributeValue::Visible) ==
- XFA_AttributeValue::Visible;
+ auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
+ return !value.has_value() || value.value() == XFA_AttributeValue::Visible;
}
bool CXFA_Caption::IsHidden() {
- return JSObject()
- ->TryEnum(XFA_Attribute::Presence, true)
- .value_or(XFA_AttributeValue::Visible) ==
- XFA_AttributeValue::Hidden;
+ auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
+ return !value.has_value() || value.value() == XFA_AttributeValue::Hidden;
}
XFA_AttributeValue CXFA_Caption::GetPlacementType() {
- return JSObject()
- ->TryEnum(XFA_Attribute::Placement, true)
- .value_or(XFA_AttributeValue::Left);
+ auto value = JSObject()->TryEnum(XFA_Attribute::Placement, true);
+ return value.value_or(XFA_AttributeValue::Left);
}
float CXFA_Caption::GetReserve() const {
diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
index a579c13..e4ede0a 100644
--- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
@@ -672,10 +672,8 @@
float CXFA_ItemLayoutProcessor::FindSplitPos(float fProposedSplitPos) {
ASSERT(m_pLayoutItem);
- XFA_AttributeValue eLayout = GetFormNode()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Layout, true)
- .value_or(XFA_AttributeValue::Position);
+ auto value = GetFormNode()->JSObject()->TryEnum(XFA_Attribute::Layout, true);
+ XFA_AttributeValue eLayout = value.value_or(XFA_AttributeValue::Position);
bool bCalculateMargin = eLayout != XFA_AttributeValue::Position;
while (fProposedSplitPos > XFA_LAYOUT_FLOAT_PERCISION) {
bool bAppChange = false;
@@ -691,11 +689,10 @@
CXFA_ContentLayoutItem* pLayoutItem,
CXFA_ContentLayoutItem* pSecondParent,
float fSplitPos) {
- float fCurTopMargin = 0, fCurBottomMargin = 0;
- XFA_AttributeValue eLayout = GetFormNode()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Layout, true)
- .value_or(XFA_AttributeValue::Position);
+ float fCurTopMargin = 0;
+ float fCurBottomMargin = 0;
+ auto value = GetFormNode()->JSObject()->TryEnum(XFA_Attribute::Layout, true);
+ XFA_AttributeValue eLayout = value.value_or(XFA_AttributeValue::Position);
bool bCalculateMargin = true;
if (eLayout == XFA_AttributeValue::Position)
bCalculateMargin = false;
@@ -1123,11 +1120,9 @@
return;
m_pLayoutItem = CreateContentLayoutItem(GetFormNode());
- bool bIgnoreXY = (GetFormNode()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Layout, true)
- .value_or(XFA_AttributeValue::Position) !=
- XFA_AttributeValue::Position);
+ auto value = GetFormNode()->JSObject()->TryEnum(XFA_Attribute::Layout, true);
+ bool bIgnoreXY = value.value_or(XFA_AttributeValue::Position) !=
+ XFA_AttributeValue::Position;
bool bContainerWidthAutoSize = true;
bool bContainerHeightAutoSize = true;
CFX_SizeF containerSize = CalculateContainerSpecifiedSize(
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 3c29bf7..9f7426e 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1288,9 +1288,9 @@
XFA_AttributeValue CXFA_Node::GetIntact() {
CXFA_Keep* pKeep = GetFirstChildByClass<CXFA_Keep>(XFA_Element::Keep);
- XFA_AttributeValue eLayoutType = JSObject()
- ->TryEnum(XFA_Attribute::Layout, true)
- .value_or(XFA_AttributeValue::Position);
+ auto layout = JSObject()->TryEnum(XFA_Attribute::Layout, true);
+ XFA_AttributeValue eLayoutType =
+ layout.value_or(XFA_AttributeValue::Position);
if (pKeep) {
Optional<XFA_AttributeValue> intact =
pKeep->JSObject()->TryEnum(XFA_Attribute::Intact, false);
@@ -1340,10 +1340,9 @@
if (parent->GetIntact() != XFA_AttributeValue::None)
return XFA_AttributeValue::ContentArea;
+ auto value = parent->JSObject()->TryEnum(XFA_Attribute::Layout, true);
XFA_AttributeValue eParLayout =
- parent->JSObject()
- ->TryEnum(XFA_Attribute::Layout, true)
- .value_or(XFA_AttributeValue::Position);
+ value.value_or(XFA_AttributeValue::Position);
if (eParLayout == XFA_AttributeValue::Position ||
eParLayout == XFA_AttributeValue::Row ||
eParLayout == XFA_AttributeValue::Table) {
@@ -3592,10 +3591,8 @@
XFA_VERSION version = docView->GetDoc()->GetXFADoc()->GetCurVersionMode();
bool bCanSplitNoContent = false;
- XFA_AttributeValue eLayoutMode = GetParent()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Layout, true)
- .value_or(XFA_AttributeValue::Position);
+ auto value = GetParent()->JSObject()->TryEnum(XFA_Attribute::Layout, true);
+ XFA_AttributeValue eLayoutMode = value.value_or(XFA_AttributeValue::Position);
if ((eLayoutMode == XFA_AttributeValue::Position ||
eLayoutMode == XFA_AttributeValue::Tb ||
eLayoutMode == XFA_AttributeValue::Row ||
@@ -4927,9 +4924,8 @@
}
bool CXFA_Node::PresenceRequiresSpace() const {
- XFA_AttributeValue ePresence = JSObject()
- ->TryEnum(XFA_Attribute::Presence, true)
- .value_or(XFA_AttributeValue::Visible);
+ auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
+ XFA_AttributeValue ePresence = value.value_or(XFA_AttributeValue::Visible);
return ePresence == XFA_AttributeValue::Visible ||
ePresence == XFA_AttributeValue::Invisible;
}
diff --git a/xfa/fxfa/parser/cxfa_radial.cpp b/xfa/fxfa/parser/cxfa_radial.cpp
index c85beb8..dbc8319 100644
--- a/xfa/fxfa/parser/cxfa_radial.cpp
+++ b/xfa/fxfa/parser/cxfa_radial.cpp
@@ -43,10 +43,8 @@
CXFA_Radial::~CXFA_Radial() = default;
bool CXFA_Radial::IsToEdge() {
- return JSObject()
- ->TryEnum(XFA_Attribute::Type, true)
- .value_or(XFA_AttributeValue::ToEdge) ==
- XFA_AttributeValue::ToEdge;
+ auto value = JSObject()->TryEnum(XFA_Attribute::Type, true);
+ return !value.has_value() || value.value() == XFA_AttributeValue::ToEdge;
}
CXFA_Color* CXFA_Radial::GetColorIfExists() {