From 46ab5abf23910983663b3daeb6dc2f6a98ee24a8 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 9 Oct 2018 23:15:56 +0000 Subject: Remove some string comparisons in CPDF_Action. We have a string to enum tokenizer. Use it. Re-order .cpp to match .h in one place. Change-Id: I6835826d5c7be599265ff05f2369da4f2bcc789c Reviewed-on: https://pdfium-review.googlesource.com/c/43791 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfdoc/cpdf_action.cpp | 70 +++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'core') diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp index 6238b05299..6e9e9f7b68 100644 --- a/core/fpdfdoc/cpdf_action.cpp +++ b/core/fpdfdoc/cpdf_action.cpp @@ -27,14 +27,26 @@ CPDF_Action::CPDF_Action(const CPDF_Dictionary* pDict) : m_pDict(pDict) {} CPDF_Action::CPDF_Action(const CPDF_Action& that) = default; -CPDF_Action::~CPDF_Action() {} +CPDF_Action::~CPDF_Action() = default; -CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { +CPDF_Action::ActionType CPDF_Action::GetType() const { if (!m_pDict) - return CPDF_Dest(); + return Unknown; + + ByteString csType = m_pDict->GetStringFor("S"); + if (csType.IsEmpty()) + return Unknown; - ByteString type = m_pDict->GetStringFor("S"); - if (type != "GoTo" && type != "GoToR") + for (int i = 0; g_sATypes[i]; ++i) { + if (csType == g_sATypes[i]) + return static_cast(i); + } + return Unknown; +} + +CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { + ActionType type = GetType(); + if (type != GoTo && type != GoToR) return CPDF_Dest(); const CPDF_Object* pDest = m_pDict->GetDirectObjectFor("D"); @@ -50,25 +62,10 @@ CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { return CPDF_Dest(); } -CPDF_Action::ActionType CPDF_Action::GetType() const { - if (!m_pDict) - return Unknown; - - ByteString csType = m_pDict->GetStringFor("S"); - if (csType.IsEmpty()) - return Unknown; - - for (int i = 0; g_sATypes[i]; ++i) { - if (csType == g_sATypes[i]) - return static_cast(i); - } - return Unknown; -} - WideString CPDF_Action::GetFilePath() const { - ByteString type = m_pDict->GetStringFor("S"); - if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && - type != "ImportData") { + ActionType type = GetType(); + if (type != GoToR && type != Launch && type != SubmitForm && + type != ImportData) { return WideString(); } @@ -76,24 +73,23 @@ WideString CPDF_Action::GetFilePath() const { if (pFile) return CPDF_FileSpec(pFile).GetFileName(); - if (type == "Launch") { - const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win"); - if (pWinDict) { - return WideString::FromLocal( - pWinDict->GetStringFor(pdfium::stream::kF).AsStringView()); - } - } - return WideString(); + if (type != Launch) + return WideString(); + + const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win"); + if (!pWinDict) + return WideString(); + + return WideString::FromLocal( + pWinDict->GetStringFor(pdfium::stream::kF).AsStringView()); } ByteString CPDF_Action::GetURI(const CPDF_Document* pDoc) const { - ByteString csURI; - if (!m_pDict) - return csURI; - if (m_pDict->GetStringFor("S") != "URI") - return csURI; + ActionType type = GetType(); + if (type != URI) + return ByteString(); - csURI = m_pDict->GetStringFor("URI"); + ByteString csURI = m_pDict->GetStringFor("URI"); const CPDF_Dictionary* pRoot = pDoc->GetRoot(); const CPDF_Dictionary* pURI = pRoot->GetDictFor("URI"); if (pURI) { -- cgit v1.2.3