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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri May 24 11:28:58 UTC 2019


 writerfilter/source/rtftok/rtftokenizer.cxx |   35 +++++++++++++---------------
 writerfilter/source/rtftok/rtftokenizer.hxx |    5 ++--
 2 files changed, 20 insertions(+), 20 deletions(-)

New commits:
commit d6865e5cec34f5f521e0f9ec4ef3c7ad04503cfe
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri May 24 11:52:30 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri May 24 13:27:43 2019 +0200

    use std::unordered_map in RTFTokenizer
    
    to speed up
    
        make sw.check
    
    Using a --enable-dbgutil --enable-optimised build, this takes my runtime
    from 6m03 to 3m43
    
    Change-Id: I79d2345c361d99d4a1c4402a4b7008bbb59b8184
    Reviewed-on: https://gerrit.libreoffice.org/72902
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    Tested-by: Jenkins

diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index cccf47ef5978..b2a1fea346e5 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -27,8 +27,8 @@ namespace writerfilter
 {
 namespace rtftok
 {
-std::vector<RTFSymbol> RTFTokenizer::s_aRTFControlWords;
-bool RTFTokenizer::s_bControlWordsSorted;
+std::unordered_map<OString, RTFSymbol> RTFTokenizer::s_aRTFControlWords;
+bool RTFTokenizer::s_bControlWordsInitialised;
 std::vector<RTFMathSymbol> RTFTokenizer::s_aRTFMathControlWords;
 bool RTFTokenizer::s_bMathControlWordsSorted;
 
@@ -42,12 +42,12 @@ RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream,
     , m_nLineStartPos(0)
     , m_nGroupStart(0)
 {
-    if (!RTFTokenizer::s_bControlWordsSorted)
+    if (!RTFTokenizer::s_bControlWordsInitialised)
     {
-        RTFTokenizer::s_bControlWordsSorted = true;
-        s_aRTFControlWords
-            = std::vector<RTFSymbol>(aRTFControlWords, aRTFControlWords + nRTFControlWords);
-        std::sort(s_aRTFControlWords.begin(), s_aRTFControlWords.end());
+        RTFTokenizer::s_bControlWordsInitialised = true;
+        for (int i = 0; i < nRTFControlWords; ++i)
+            s_aRTFControlWords.emplace(OString(aRTFControlWords[i].GetKeyword()),
+                                       aRTFControlWords[i]);
     }
     if (!RTFTokenizer::s_bMathControlWordsSorted)
     {
@@ -270,10 +270,8 @@ RTFError RTFTokenizer::dispatchKeyword(OString const& rKeyword, bool bParam, int
     SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": keyword '\\" << rKeyword << "' with param? "
                                                << (bParam ? 1 : 0) << " param val: '"
                                                << (bParam ? nParam : 0) << "'");
-    RTFSymbol aSymbol(rKeyword.getStr());
-    auto low = std::lower_bound(s_aRTFControlWords.begin(), s_aRTFControlWords.end(), aSymbol);
-    int i = low - s_aRTFControlWords.begin();
-    if (low == s_aRTFControlWords.end() || aSymbol < *low)
+    auto findIt = s_aRTFControlWords.find(rKeyword);
+    if (findIt == s_aRTFControlWords.end())
     {
         SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": unknown keyword '\\" << rKeyword << "'");
         RTFSkipDestination aSkip(m_rImport);
@@ -282,35 +280,36 @@ RTFError RTFTokenizer::dispatchKeyword(OString const& rKeyword, bool bParam, int
     }
 
     RTFError ret;
-    switch (s_aRTFControlWords[i].GetControlType())
+    RTFSymbol const& rSymbol = findIt->second;
+    switch (rSymbol.GetControlType())
     {
         case CONTROL_FLAG:
             // flags ignore any parameter by definition
-            ret = m_rImport.dispatchFlag(s_aRTFControlWords[i].GetIndex());
+            ret = m_rImport.dispatchFlag(rSymbol.GetIndex());
             if (ret != RTFError::OK)
                 return ret;
             break;
         case CONTROL_DESTINATION:
             // same for destinations
-            ret = m_rImport.dispatchDestination(s_aRTFControlWords[i].GetIndex());
+            ret = m_rImport.dispatchDestination(rSymbol.GetIndex());
             if (ret != RTFError::OK)
                 return ret;
             break;
         case CONTROL_SYMBOL:
             // and symbols
-            ret = m_rImport.dispatchSymbol(s_aRTFControlWords[i].GetIndex());
+            ret = m_rImport.dispatchSymbol(rSymbol.GetIndex());
             if (ret != RTFError::OK)
                 return ret;
             break;
         case CONTROL_TOGGLE:
-            ret = m_rImport.dispatchToggle(s_aRTFControlWords[i].GetIndex(), bParam, nParam);
+            ret = m_rImport.dispatchToggle(rSymbol.GetIndex(), bParam, nParam);
             if (ret != RTFError::OK)
                 return ret;
             break;
         case CONTROL_VALUE:
             if (!bParam)
-                nParam = s_aRTFControlWords[i].GetDefValue();
-            ret = m_rImport.dispatchValue(s_aRTFControlWords[i].GetIndex(), nParam);
+                nParam = rSymbol.GetDefValue();
+            ret = m_rImport.dispatchValue(rSymbol.GetIndex(), nParam);
             if (ret != RTFError::OK)
                 return ret;
             break;
diff --git a/writerfilter/source/rtftok/rtftokenizer.hxx b/writerfilter/source/rtftok/rtftokenizer.hxx
index 7ff91a52fc2f..4cc3f159fe5b 100644
--- a/writerfilter/source/rtftok/rtftokenizer.hxx
+++ b/writerfilter/source/rtftok/rtftokenizer.hxx
@@ -13,6 +13,7 @@
 #include "rtflistener.hxx"
 
 #include <vector>
+#include <unordered_map>
 
 #include <com/sun/star/uno/Reference.h>
 
@@ -67,8 +68,8 @@ private:
     SvStream* m_pInStream;
     css::uno::Reference<css::task::XStatusIndicator> const& m_xStatusIndicator;
     // This is the same as aRTFControlWords, but sorted
-    static std::vector<RTFSymbol> s_aRTFControlWords;
-    static bool s_bControlWordsSorted;
+    static std::unordered_map<OString, RTFSymbol> s_aRTFControlWords;
+    static bool s_bControlWordsInitialised;
     // This is the same as aRTFMathControlWords, but sorted
     static std::vector<RTFMathSymbol> s_aRTFMathControlWords;
     static bool s_bMathControlWordsSorted;


More information about the Libreoffice-commits mailing list