From 9a48fd1aabf105b168f5d8fc26549ae0d41d002e Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 27 Nov 2017 19:36:26 +0000 Subject: Fold XFA_GetAttributeByName into CXFA_Node::NameToAttribute This CL removes the xfa_utils helper and does the work directly in CXFA_Node. Change-Id: I4f7cac9cb6d2a53ac5627f50a2f066f79fc22a31 Reviewed-on: https://pdfium-review.googlesource.com/19290 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_node.cpp | 14 +++++++++++--- xfa/fxfa/parser/xfa_utils.cpp | 15 --------------- xfa/fxfa/parser/xfa_utils.h | 1 - xfa/fxfa/parser/xfa_utils_unittest.cpp | 9 --------- 4 files changed, 11 insertions(+), 28 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 4402208900..ee2a6df071 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -145,10 +145,18 @@ WideString CXFA_Node::AttributeToName(XFA_Attribute attr) { // static XFA_Attribute CXFA_Node::NameToAttribute(const WideStringView& name) { - const XFA_ATTRIBUTEINFO* attr = XFA_GetAttributeByName(name); - if (!attr) + if (name.IsEmpty()) return XFA_Attribute::Unknown; - return attr->eName; + + auto* it = std::lower_bound(g_XFAAttributeData, + g_XFAAttributeData + g_iXFAAttributeCount, + FX_HashCode_GetW(name, false), + [](const XFA_ATTRIBUTEINFO& arg, uint32_t hash) { + return arg.uHash < hash; + }); + if (it != g_XFAAttributeData + g_iXFAAttributeCount && name == it->pName) + return it->eName; + return XFA_Attribute::Unknown; } CXFA_Node::CXFA_Node(CXFA_Document* pDoc, diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index 03b8943a1f..7fb5ff573d 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp @@ -268,21 +268,6 @@ bool XFA_GetAttributeDefaultValue(void*& pValue, return false; } -const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const WideStringView& wsName) { - if (wsName.IsEmpty()) - return nullptr; - - auto* it = std::lower_bound(g_XFAAttributeData, - g_XFAAttributeData + g_iXFAAttributeCount, - FX_HashCode_GetW(wsName, false), - [](const XFA_ATTRIBUTEINFO& arg, uint32_t hash) { - return arg.uHash < hash; - }); - if (it != g_XFAAttributeData + g_iXFAAttributeCount && wsName == it->pName) - return it; - return nullptr; -} - const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_Attribute eName) { ASSERT(static_cast(eName) < g_iXFAAttributeCount); return g_XFAAttributeData + static_cast(eName); diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 08092563e8..afc1076d35 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -54,7 +54,6 @@ bool XFA_GetAttributeDefaultValue(void*& pValue, XFA_Attribute eAttribute, XFA_AttributeType eType, uint32_t dwPacket); -const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const WideStringView& wsName); const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_Attribute eName); const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( const WideStringView& wsName); diff --git a/xfa/fxfa/parser/xfa_utils_unittest.cpp b/xfa/fxfa/parser/xfa_utils_unittest.cpp index bd2c89d554..b27cdaa36e 100644 --- a/xfa/fxfa/parser/xfa_utils_unittest.cpp +++ b/xfa/fxfa/parser/xfa_utils_unittest.cpp @@ -23,15 +23,6 @@ TEST(XfaUtilsImpTest, XFA_MapRotation) { } } -TEST(XFAUtilsTest, GetAttributeByName) { - EXPECT_EQ(nullptr, XFA_GetAttributeByName(L"")); - EXPECT_EQ(nullptr, XFA_GetAttributeByName(L"nonesuch")); - EXPECT_EQ(XFA_Attribute::H, XFA_GetAttributeByName(L"h")->eName); - EXPECT_EQ(XFA_Attribute::Short, XFA_GetAttributeByName(L"short")->eName); - EXPECT_EQ(XFA_Attribute::DecipherOnly, - XFA_GetAttributeByName(L"decipherOnly")->eName); -} - TEST(XFAUtilsTest, GetAttributeEnumByName) { EXPECT_EQ(nullptr, XFA_GetAttributeEnumByName(L"")); EXPECT_EQ(nullptr, XFA_GetAttributeEnumByName(L"nonesuch")); -- cgit v1.2.3