From f328d0d378b8df8a3416988d96c34f1d3f9d26d1 Mon Sep 17 00:00:00 2001 From: thestig Date: Tue, 18 Oct 2016 15:38:23 -0700 Subject: Make Document::m_IconList a vector of IconElements. There's no need for std::list>. Review-Url: https://codereview.chromium.org/2428743004 --- fpdfsdk/javascript/Document.cpp | 52 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'fpdfsdk/javascript/Document.cpp') diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 0b08f66f33..4b597ae127 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -1256,8 +1256,7 @@ FX_BOOL Document::addIcon(IJS_Context* cc, return FALSE; } - m_IconList.push_back(std::unique_ptr( - new IconElement(swIconName, (Icon*)pEmbedObj))); + m_Icons.push_back(IconElement(swIconName, static_cast(pEmbedObj))); return TRUE; } @@ -1270,7 +1269,7 @@ FX_BOOL Document::icons(IJS_Context* cc, } CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - if (m_IconList.empty()) { + if (m_Icons.empty()) { vp.GetJSValue()->SetNull(pRuntime); return TRUE; } @@ -1278,7 +1277,7 @@ FX_BOOL Document::icons(IJS_Context* cc, CJS_Array Icons; int i = 0; - for (const auto& pIconElement : m_IconList) { + for (const auto& element : m_Icons) { v8::Local pObj = pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); if (pObj.IsEmpty()) @@ -1289,12 +1288,12 @@ FX_BOOL Document::icons(IJS_Context* cc, if (!pJS_Icon) return FALSE; - Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); + Icon* pIcon = static_cast(pJS_Icon->GetEmbedObject()); if (!pIcon) return FALSE; - pIcon->SetStream(pIconElement->IconStream->GetStream()); - pIcon->SetIconName(pIconElement->IconName); + pIcon->SetStream(element.IconStream->GetStream()); + pIcon->SetIconName(element.IconName); Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); } @@ -1311,35 +1310,34 @@ FX_BOOL Document::getIcon(IJS_Context* cc, return FALSE; } - if (m_IconList.empty()) + if (m_Icons.empty()) return FALSE; CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); - for (const auto& pIconElement : m_IconList) { - if (pIconElement->IconName == swIconName) { - Icon* pRetIcon = pIconElement->IconStream; + for (const auto& element : m_Icons) { + if (element.IconName != swIconName) + continue; - v8::Local pObj = - pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); - if (pObj.IsEmpty()) - return FALSE; + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); + if (pObj.IsEmpty()) + return FALSE; - CJS_Icon* pJS_Icon = - static_cast(pRuntime->GetObjectPrivate(pObj)); - if (!pJS_Icon) - return FALSE; + CJS_Icon* pJS_Icon = + static_cast(pRuntime->GetObjectPrivate(pObj)); + if (!pJS_Icon) + return FALSE; - Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); - if (!pIcon) - return FALSE; + Icon* pIcon = static_cast(pJS_Icon->GetEmbedObject()); + if (!pIcon) + return FALSE; - pIcon->SetIconName(swIconName); - pIcon->SetStream(pRetIcon->GetStream()); - vRet = CJS_Value(pRuntime, pJS_Icon); - return TRUE; - } + pIcon->SetIconName(swIconName); + pIcon->SetStream(element.IconStream->GetStream()); + vRet = CJS_Value(pRuntime, pJS_Icon); + return TRUE; } return FALSE; -- cgit v1.2.3