Change XFA_GetElementByName() to take a WideStringView.
Change-Id: I4cc0baff1bbc4fd320150ac76480e6fdbf364ebc
Reviewed-on: https://pdfium-review.googlesource.com/c/47330
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp
index 3eac0c5..eb5c955 100644
--- a/fxjs/xfa/cfxjse_engine.cpp
+++ b/fxjs/xfa/cfxjse_engine.cpp
@@ -368,8 +368,9 @@
CXFA_Object* pObject =
lpScriptContext->GetVariablesThis(pOriginalObject, false);
WideString wsPropName = WideString::FromUTF8(szPropName);
- Optional<XFA_SCRIPTATTRIBUTEINFO> info = XFA_GetScriptAttributeByName(
- pObject->GetElementType(), wsPropName.AsStringView());
+ WideStringView wsPropNameView = wsPropName.AsStringView();
+ Optional<XFA_SCRIPTATTRIBUTEINFO> info =
+ XFA_GetScriptAttributeByName(pObject->GetElementType(), wsPropNameView);
if (info.has_value()) {
CJX_Object* jsObject = pObject->JSObject();
(jsObject->*(info.value().callback))(pReturnValue, true,
@@ -378,17 +379,17 @@
}
if (pObject->IsNode()) {
- if (wsPropName[0] == '#')
- wsPropName = wsPropName.Right(wsPropName.GetLength() - 1);
+ if (wsPropNameView[0] == '#')
+ wsPropNameView = wsPropNameView.Right(wsPropNameView.GetLength() - 1);
CXFA_Node* pNode = ToNode(pObject);
CXFA_Node* pPropOrChild = nullptr;
- XFA_Element eType = XFA_GetElementByName(wsPropName);
+ XFA_Element eType = XFA_GetElementByName(wsPropNameView);
if (eType != XFA_Element::Unknown) {
pPropOrChild =
pNode->JSObject()->GetOrCreateProperty<CXFA_Node>(0, eType);
} else {
- pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringView());
+ pPropOrChild = pNode->GetFirstChildByName(wsPropNameView);
}
if (pPropOrChild) {
@@ -678,13 +679,12 @@
pNodeHelper->m_pCreateParent = ToNode(rndFind.m_CurObject);
pNodeHelper->m_iCreateCount = 1;
}
- bool bCreate = pNodeHelper->CreateNode(
- rndFind.m_wsName, rndFind.m_wsCondition,
- nStart ==
- pdfium::base::checked_cast<int32_t>(wsExpression.GetLength()),
- this);
- if (bCreate)
+ int32_t checked_length =
+ pdfium::base::checked_cast<int32_t>(wsExpression.GetLength());
+ if (pNodeHelper->CreateNode(rndFind.m_wsName, rndFind.m_wsCondition,
+ nStart == checked_length, this)) {
continue;
+ }
}
break;
}
diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp
index 29bb17c..9f165f5 100644
--- a/fxjs/xfa/cfxjse_resolveprocessor.cpp
+++ b/fxjs/xfa/cfxjse_resolveprocessor.cpp
@@ -348,7 +348,7 @@
0, XFA_Element::Occur);
}
} else {
- XFA_Element eType = XFA_GetElementByName(wsName);
+ XFA_Element eType = XFA_GetElementByName(wsName.AsStringView());
if (eType == XFA_Element::PageSet) {
pProp = curNode->AsNode()->JSObject()->GetProperty<CXFA_Node>(0, eType);
} else if (eType != XFA_Element::Unknown) {
diff --git a/fxjs/xfa/cjx_model.cpp b/fxjs/xfa/cjx_model.cpp
index ef6ab66..f72fbc4 100644
--- a/fxjs/xfa/cjx_model.cpp
+++ b/fxjs/xfa/cjx_model.cpp
@@ -47,7 +47,7 @@
nameSpace = runtime->ToWideString(params[2]);
WideString tagName = runtime->ToWideString(params[0]);
- XFA_Element eType = XFA_GetElementByName(tagName);
+ XFA_Element eType = XFA_GetElementByName(tagName.AsStringView());
CXFA_Node* pNewNode = GetXFANode()->CreateSamePacketNode(eType);
if (!pNewNode)
return CJS_Result::Success(runtime->NewNull());
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index bce17f0..f7fac81 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -206,8 +206,8 @@
WideString expression = runtime->ToWideString(params[0]);
int32_t iValue = params.size() >= 2 ? runtime->ToInt32(params[1]) : 0;
- CXFA_Node* pNode =
- GetOrCreateProperty<CXFA_Node>(iValue, XFA_GetElementByName(expression));
+ CXFA_Node* pNode = GetOrCreateProperty<CXFA_Node>(
+ iValue, XFA_GetElementByName(expression.AsStringView()));
if (!pNode)
return CJS_Result::Success(runtime->NewNull());
@@ -234,7 +234,7 @@
bool bParent = params.size() < 2 || runtime->ToBoolean(params[1]);
int32_t iIndex = params.size() == 3 ? runtime->ToInt32(params[2]) : 0;
- XFA_Element eType = XFA_GetElementByName(expression);
+ XFA_Element eType = XFA_GetElementByName(expression.AsStringView());
bool bHas = !!GetOrCreateProperty<CXFA_Node>(iIndex, eType);
if (!bHas && bParent && GetXFANode()->GetParent()) {
// Also check on the parent.
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index 2264217..1ab2c21 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -695,7 +695,7 @@
case FX_XMLNODE_Element: {
CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLChild);
WideString wsTagName = pXMLElement->GetLocalTagName();
- XFA_Element eType = XFA_GetElementByName(wsTagName);
+ XFA_Element eType = XFA_GetElementByName(wsTagName.AsStringView());
if (eType == XFA_Element::Unknown)
continue;
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.cpp b/xfa/fxfa/parser/cxfa_nodehelper.cpp
index 14bc1b1..79c9834 100644
--- a/xfa/fxfa/parser/cxfa_nodehelper.cpp
+++ b/xfa/fxfa/parser/cxfa_nodehelper.cpp
@@ -320,7 +320,7 @@
CreateNodeForCondition(wsCondition);
}
if (bIsClassName) {
- XFA_Element eType = XFA_GetElementByName(wsName);
+ XFA_Element eType = XFA_GetElementByName(wsName.AsStringView());
if (eType == XFA_Element::Unknown)
return false;
diff --git a/xfa/fxfa/parser/xfa_basic_data.cpp b/xfa/fxfa/parser/xfa_basic_data.cpp
index 72c8790..e673cde 100644
--- a/xfa/fxfa/parser/xfa_basic_data.cpp
+++ b/xfa/fxfa/parser/xfa_basic_data.cpp
@@ -247,8 +247,8 @@
return g_ElementTable[static_cast<size_t>(elem)].name;
}
-XFA_Element XFA_GetElementByName(const WideString& name) {
- uint32_t hash = FX_HashCode_GetW(name.AsStringView(), false);
+XFA_Element XFA_GetElementByName(WideStringView name) {
+ uint32_t hash = FX_HashCode_GetW(name, false);
auto* elem = std::lower_bound(
std::begin(g_ElementTable), std::end(g_ElementTable), hash,
[](const ElementRecord& a, uint32_t hash) { return a.hash < hash; });
diff --git a/xfa/fxfa/parser/xfa_basic_data.h b/xfa/fxfa/parser/xfa_basic_data.h
index c6ce222..4c3e0c7 100644
--- a/xfa/fxfa/parser/xfa_basic_data.h
+++ b/xfa/fxfa/parser/xfa_basic_data.h
@@ -36,7 +36,7 @@
Optional<XFA_PACKETINFO> XFA_GetPacketByName(WideStringView wsName);
ByteStringView XFA_ElementToName(XFA_Element elem);
-XFA_Element XFA_GetElementByName(const WideString& name);
+XFA_Element XFA_GetElementByName(WideStringView name);
ByteStringView XFA_AttributeToName(XFA_Attribute attr);
Optional<XFA_ATTRIBUTEINFO> XFA_GetAttributeByName(WideStringView name);