[Libreoffice-commits] core.git: formula/source include/formula include/svl sc/inc sc/source svl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Jan 25 16:55:38 UTC 2021


 formula/source/core/api/token.cxx     |   12 +++++++-----
 include/formula/token.hxx             |    8 ++++----
 include/svl/sharedstring.hxx          |    2 +-
 sc/inc/formulacell.hxx                |    6 +++---
 sc/inc/formularesult.hxx              |    2 +-
 sc/inc/token.hxx                      |   12 ++++++------
 sc/source/core/data/formulacell.cxx   |    6 +++---
 sc/source/core/inc/interpre.hxx       |    2 +-
 sc/source/core/tool/formularesult.cxx |    2 +-
 sc/source/core/tool/interpr4.cxx      |    2 +-
 sc/source/core/tool/token.cxx         |   12 ++++++------
 svl/source/misc/sharedstring.cxx      |   10 ++++++----
 12 files changed, 40 insertions(+), 36 deletions(-)

New commits:
commit aa98ed61a7b1e50bcc4f64ceaea3bb0cda360bb4
Author:     Noel Grandin <noel at peralex.com>
AuthorDate: Mon Jan 25 14:43:05 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jan 25 17:54:54 2021 +0100

    tdf#92456 improve VLOOKUP perf
    
    shave 5% of the time here - ref-counting triggered by copying
    svl::SharedString is significant, so return by const&
    instead of by value
    
    Change-Id: Ic702632da45d75dddab33d6ce1e6f1097ff70de9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109900
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 37dd26979ced..6464f3d52b0f 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -209,10 +209,12 @@ void FormulaToken::SetDoubleType( sal_Int16 )
     assert( !"virtual dummy called" );
 }
 
-svl::SharedString FormulaToken::GetString() const
+const svl::SharedString INVALID_STRING;
+
+const svl::SharedString & FormulaToken::GetString() const
 {
     SAL_WARN( "formula.core", "FormulaToken::GetString: virtual dummy called" );
-    return svl::SharedString(); // invalid string
+    return INVALID_STRING; // invalid string
 }
 
 void FormulaToken::SetString( const svl::SharedString& )
@@ -1877,7 +1879,7 @@ FormulaToken* FormulaStringToken::Clone() const
     return new FormulaStringToken(*this);
 }
 
-svl::SharedString FormulaStringToken::GetString() const
+const svl::SharedString & FormulaStringToken::GetString() const
 {
     return maString;
 }
@@ -1903,7 +1905,7 @@ FormulaToken* FormulaStringOpToken::Clone() const
     return new FormulaStringOpToken(*this);
 }
 
-svl::SharedString FormulaStringOpToken::GetString() const
+const svl::SharedString & FormulaStringOpToken::GetString() const
 {
     return maString;
 }
@@ -1943,7 +1945,7 @@ bool FormulaErrorToken::operator==( const FormulaToken& r ) const
 }
 double          FormulaMissingToken::GetDouble() const       { return 0.0; }
 
-svl::SharedString FormulaMissingToken::GetString() const
+const svl::SharedString & FormulaMissingToken::GetString() const
 {
     return svl::SharedString::getEmptyString();
 }
diff --git a/include/formula/token.hxx b/include/formula/token.hxx
index 4fc6b382d4cd..3fa00e89339f 100644
--- a/include/formula/token.hxx
+++ b/include/formula/token.hxx
@@ -181,7 +181,7 @@ public:
     virtual double&             GetDoubleAsReference();
     virtual sal_Int16           GetDoubleType() const;
     virtual void                SetDoubleType( sal_Int16 nType );
-    virtual svl::SharedString   GetString() const;
+    virtual const svl::SharedString & GetString() const;
     virtual void                SetString( const svl::SharedString& rStr );
     virtual sal_uInt16          GetIndex() const;
     virtual void                SetIndex( sal_uInt16 n );
@@ -320,7 +320,7 @@ public:
     FormulaStringToken( const FormulaStringToken& r );
 
     virtual FormulaToken* Clone() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual void SetString( const svl::SharedString& rStr ) override;
     virtual bool operator==( const FormulaToken& rToken ) const override;
 };
@@ -336,7 +336,7 @@ public:
     FormulaStringOpToken( const FormulaStringOpToken& r );
 
     virtual FormulaToken* Clone() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual void SetString( const svl::SharedString& rStr ) override;
     virtual bool operator==( const FormulaToken& rToken ) const override;
 };
@@ -391,7 +391,7 @@ public:
 
     virtual FormulaToken*       Clone() const override { return new FormulaMissingToken(*this); }
     virtual double              GetDouble() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual bool                operator==( const FormulaToken& rToken ) const override;
 };
 
diff --git a/include/svl/sharedstring.hxx b/include/svl/sharedstring.hxx
index 71aad67ba2c6..f74824adeec2 100644
--- a/include/svl/sharedstring.hxx
+++ b/include/svl/sharedstring.hxx
@@ -21,7 +21,7 @@ class SVL_DLLPUBLIC SharedString
     rtl_uString* mpDataIgnoreCase;
 public:
 
-    static SharedString getEmptyString();
+    static const SharedString & getEmptyString();
 
     SharedString();
     SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase );
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 9be8b84df8a9..74d571102a2b 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -320,7 +320,7 @@ public:
     bool            IsValueNoError();
     bool            IsValueNoError() const;
     double          GetValue();
-    svl::SharedString GetString();
+    const svl::SharedString & GetString();
 
     /**
      * Get a numeric value without potentially triggering re-calculation.
@@ -330,7 +330,7 @@ public:
     /**
      * Get a string value without potentially triggering re-calculation.
      */
-    svl::SharedString GetRawString() const;
+    const svl::SharedString & GetRawString() const;
     const ScMatrix* GetMatrix();
     bool            GetMatrixOrigin( const ScDocument& rDoc, ScAddress& rPos ) const;
     void            GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows );
@@ -407,7 +407,7 @@ public:
 
     void SetResultToken( const formula::FormulaToken* pToken );
 
-    svl::SharedString GetResultString() const;
+    const svl::SharedString & GetResultString() const;
 
     bool HasHybridStringResult() const;
 
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx
index b79f4cc76a2a..d7cda54ed1d8 100644
--- a/sc/inc/formularesult.hxx
+++ b/sc/inc/formularesult.hxx
@@ -185,7 +185,7 @@ public:
 
     /** Return string if type formula::svString or formula::svHybridCell or formula::svMatrixCell and
         upper left formula::svString, else empty string. */
-    svl::SharedString GetString() const;
+    const svl::SharedString & GetString() const;
 
     /** Return matrix if type formula::svMatrixCell and ScMatrix present, else NULL. */
     ScConstMatrixRef GetMatrix() const;
diff --git a/sc/inc/token.hxx b/sc/inc/token.hxx
index 68870e962dca..8ee554c4e8d6 100644
--- a/sc/inc/token.hxx
+++ b/sc/inc/token.hxx
@@ -144,7 +144,7 @@ public:
     ScExternalSingleRefToken & operator =(ScExternalSingleRefToken &&) = delete; // due to FormulaToken
 
     virtual sal_uInt16                  GetIndex() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual const ScSingleRefData*  GetSingleRef() const override;
     virtual ScSingleRefData*          GetSingleRef() override;
     virtual bool                operator==( const formula::FormulaToken& rToken ) const override;
@@ -168,7 +168,7 @@ public:
     ScExternalDoubleRefToken & operator =(ScExternalDoubleRefToken &&) = delete; // due to FormulaToken
 
     virtual sal_uInt16                 GetIndex() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual const ScSingleRefData* GetSingleRef() const override;
     virtual ScSingleRefData*       GetSingleRef() override;
     virtual const ScSingleRefData* GetSingleRef2() const override;
@@ -195,7 +195,7 @@ public:
     ScExternalNameToken & operator =(ScExternalNameToken &&) = delete; // due to FormulaToken
 
     virtual sal_uInt16              GetIndex() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual bool                operator==( const formula::FormulaToken& rToken ) const override;
     virtual FormulaToken*       Clone() const override { return new ScExternalNameToken(*this); }
 };
@@ -286,7 +286,7 @@ public:
             bool                IsInherited() const { return bInherited; }
             bool                IsDisplayedAsString() const { return bDisplayedAsString; }
     virtual double              GetDouble() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual bool                operator==( const formula::FormulaToken& rToken ) const override;
     virtual FormulaToken*       Clone() const override { return new ScEmptyCellToken(*this); }
 };
@@ -306,7 +306,7 @@ public:
     ScMatrixCellResultToken( const ScMatrixCellResultToken& );
     virtual ~ScMatrixCellResultToken() override;
     virtual double              GetDouble() const override;
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual const ScMatrix*     GetMatrix() const override;
     virtual bool                operator==( const formula::FormulaToken& rToken ) const override;
     virtual FormulaToken*       Clone() const override;
@@ -391,7 +391,7 @@ public:
     bool IsEmptyDisplayedAsString() const   { return mbEmptyDisplayedAsString; }
     virtual double GetDouble() const override;
 
-    virtual svl::SharedString GetString() const override;
+    virtual const svl::SharedString & GetString() const override;
     virtual bool operator==( const formula::FormulaToken& rToken ) const override;
     virtual FormulaToken* Clone() const override { return new ScHybridCellToken(*this); }
 };
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 0ba55750e57b..707acf1d355c 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2616,7 +2616,7 @@ void ScFormulaCell::SetResultToken( const formula::FormulaToken* pToken )
     aResult.SetToken(pToken);
 }
 
-svl::SharedString ScFormulaCell::GetResultString() const
+const svl::SharedString & ScFormulaCell::GetResultString() const
 {
     return aResult.GetString();
 }
@@ -2795,7 +2795,7 @@ double ScFormulaCell::GetValue()
     return GetRawValue();
 }
 
-svl::SharedString ScFormulaCell::GetString()
+const svl::SharedString & ScFormulaCell::GetString()
 {
     MaybeInterpret();
     return GetRawString();
@@ -2809,7 +2809,7 @@ double ScFormulaCell::GetRawValue() const
     return 0.0;
 }
 
-svl::SharedString ScFormulaCell::GetRawString() const
+const svl::SharedString & ScFormulaCell::GetRawString() const
 {
     if ((pCode->GetCodeError() == FormulaError::NONE) &&
             aResult.GetResultError() == FormulaError::NONE)
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 18ed429aab99..f8e5f616053c 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -1025,7 +1025,7 @@ public:
 
     FormulaError                GetError() const            { return nGlobalError; }
     formula::StackVar           GetResultType() const       { return xResult->GetType(); }
-    svl::SharedString GetStringResult() const;
+    const svl::SharedString & GetStringResult() const;
     double                      GetNumResult() const        { return xResult->GetDouble(); }
     const formula::FormulaConstTokenRef& GetResultToken() const { return xResult; }
     SvNumFormatType             GetRetFormatType() const    { return nRetFmtType; }
diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx
index f25d4c9a67fb..91af2589aa40 100644
--- a/sc/source/core/tool/formularesult.cxx
+++ b/sc/source/core/tool/formularesult.cxx
@@ -511,7 +511,7 @@ double ScFormulaResult::GetDouble() const
     return mfValue;
 }
 
-svl::SharedString ScFormulaResult::GetString() const
+const svl::SharedString & ScFormulaResult::GetString() const
 {
     if (mbToken && mpToken)
     {
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 32dbd589e3ae..e71f5ebfe2fa 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4747,7 +4747,7 @@ void ScInterpreter::AssertFormulaMatrix()
     bMatrixFormula = true;
 }
 
-svl::SharedString ScInterpreter::GetStringResult() const
+const svl::SharedString & ScInterpreter::GetStringResult() const
 {
     return xResult->GetString();
 }
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 91e73e4ac49f..29427bed8506 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -727,7 +727,7 @@ sal_uInt16 ScExternalSingleRefToken::GetIndex() const
     return mnFileId;
 }
 
-svl::SharedString ScExternalSingleRefToken::GetString() const
+const svl::SharedString & ScExternalSingleRefToken::GetString() const
 {
     return maTabName;
 }
@@ -773,7 +773,7 @@ sal_uInt16 ScExternalDoubleRefToken::GetIndex() const
     return mnFileId;
 }
 
-svl::SharedString ScExternalDoubleRefToken::GetString() const
+const svl::SharedString & ScExternalDoubleRefToken::GetString() const
 {
     return maTabName;
 }
@@ -836,7 +836,7 @@ sal_uInt16 ScExternalNameToken::GetIndex() const
     return mnFileId;
 }
 
-svl::SharedString ScExternalNameToken::GetString() const
+const svl::SharedString & ScExternalNameToken::GetString() const
 {
     return maName;
 }
@@ -956,7 +956,7 @@ ScJumpMatrixToken::~ScJumpMatrixToken()
 
 double          ScEmptyCellToken::GetDouble() const     { return 0.0; }
 
-svl::SharedString ScEmptyCellToken::GetString() const
+const svl::SharedString & ScEmptyCellToken::GetString() const
 {
     return svl::SharedString::getEmptyString();
 }
@@ -977,7 +977,7 @@ double          ScMatrixCellResultToken::GetDouble() const  { return xUpperLeft-
 
 ScMatrixCellResultToken::~ScMatrixCellResultToken() {}
 
-svl::SharedString ScMatrixCellResultToken::GetString() const
+const svl::SharedString & ScMatrixCellResultToken::GetString() const
 {
     return xUpperLeft->GetString();
 }
@@ -1113,7 +1113,7 @@ ScHybridCellToken::ScHybridCellToken(
 
 double ScHybridCellToken::GetDouble() const { return mfDouble; }
 
-svl::SharedString ScHybridCellToken::GetString() const
+const svl::SharedString & ScHybridCellToken::GetString() const
 {
     return maString;
 }
diff --git a/svl/source/misc/sharedstring.cxx b/svl/source/misc/sharedstring.cxx
index 9aff3eb0eab5..d3b2cac051ce 100644
--- a/svl/source/misc/sharedstring.cxx
+++ b/svl/source/misc/sharedstring.cxx
@@ -11,13 +11,15 @@
 
 namespace svl {
 
-SharedString SharedString::getEmptyString()
+/** ref-counting traffic associated with SharedString temporaries can be significant, so use a singleton here, so we can return a const& from getEmptyString */
+static OUString EMPTY(u"");
+const SharedString EMPTY_SHARED_STRING(EMPTY.pData, EMPTY.pData);
+
+const SharedString & SharedString::getEmptyString()
 {
     // unicode string array for empty string is globally shared in OUString.
     // Let's take advantage of that.
-    rtl_uString* pData = nullptr;
-    rtl_uString_new(&pData);
-    return SharedString(pData, pData);
+    return EMPTY_SHARED_STRING;
 }
 
 SharedString::SharedString() : mpData(nullptr), mpDataIgnoreCase(nullptr) {}


More information about the Libreoffice-commits mailing list