[Libreoffice-commits] core.git: writerfilter/source

Adrien Ollier (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 23 13:46:49 UTC 2019


 writerfilter/source/rtftok/rtfsprm.cxx |   28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

New commits:
commit 347b26ae3e332c206724fe5ec9d46fef38798281
Author:     Adrien Ollier <adr.ollier at hotmail.fr>
AuthorDate: Mon Jul 22 20:16:05 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Jul 23 15:45:52 2019 +0200

    better implementation of RTFSprms::find
    
    if not bFirst, then it is more efficient
    to start the search from the end.
    
    Change-Id: I89bcb3b70ada7746ab983878f2868f58b89f37a5
    Signed-off-by: Adrien Ollier <adr.ollier at hotmail.fr>
    Reviewed-on: https://gerrit.libreoffice.org/76126
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx
index b50d9b166344..109dd20474e5 100644
--- a/writerfilter/source/rtftok/rtfsprm.cxx
+++ b/writerfilter/source/rtftok/rtfsprm.cxx
@@ -59,20 +59,28 @@ std::string RTFSprm::toString() const
 
 RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst, bool bForWrite)
 {
-    RTFValue::Pointer_t pValue;
-
     if (bForWrite)
         ensureCopyBeforeWrite();
 
-    for (auto& rSprm : *m_pSprms)
-        if (rSprm.first == nKeyword)
-        {
-            if (bFirst)
-                return rSprm.second;
+    auto cmp = [&nKeyword](const std::pair<Id, RTFValue::Pointer_t>& raPair) -> bool {
+        return raPair.first == nKeyword;
+    };
 
-            pValue = rSprm.second;
-        }
-    return pValue;
+    if (bFirst)
+    {
+        auto it = std::find_if(m_pSprms->begin(), m_pSprms->end(), cmp);
+        if (it != m_pSprms->end())
+            return it->second;
+    }
+    else
+    // find last
+    {
+        auto rit = std::find_if(m_pSprms->rbegin(), m_pSprms->rend(), cmp);
+        if (rit != m_pSprms->rend())
+            return rit->second;
+    }
+
+    return RTFValue::Pointer_t{};
 }
 
 void RTFSprms::set(Id nKeyword, const RTFValue::Pointer_t& pValue, RTFOverwrite eOverwrite)


More information about the Libreoffice-commits mailing list