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

Eike Rathke erack at redhat.com
Tue Jun 14 11:34:03 UTC 2016


 formula/source/core/api/token.cxx         |    4 +--
 include/svl/sharedstring.hxx              |    2 -
 sc/inc/tokenarray.hxx                     |    6 ++---
 sc/source/core/data/column2.cxx           |    5 ++--
 sc/source/core/data/simpleformulacalc.cxx |    2 -
 sc/source/core/tool/interpr1.cxx          |    2 -
 sc/source/core/tool/interpr4.cxx          |    6 +++--
 sc/source/core/tool/reftokenhelper.cxx    |    4 +--
 sc/source/core/tool/scmatrix.cxx          |   10 ++++-----
 sc/source/core/tool/token.cxx             |   31 +++++++++++++++++-------------
 sc/source/filter/excel/tokstack.cxx       |    8 ++++---
 sc/source/filter/excel/xechart.cxx        |    2 -
 sc/source/filter/excel/xilink.cxx         |    2 -
 sc/source/filter/xml/xmlcelli.cxx         |    3 +-
 sc/source/ui/docshell/externalrefmgr.cxx  |    6 +++--
 15 files changed, 53 insertions(+), 40 deletions(-)

New commits:
commit 478613c550236d19b8254c49e5886dca1f0b8aac
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Jun 14 13:28:47 2016 +0200

    explicit svl::SharedString(const OUString&) ctor
    
    ... to prevent accidental surprises. Not interned shared strings
    constructed from OUString have mpDataIgnoreCase=nullptr so can't be used
    for case insensitive comparison.
    
    Change-Id: I03323354298a73e93b18d2796ec447c072fdefa5

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 72c0755..9c16870 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -904,12 +904,12 @@ FormulaToken* FormulaTokenArray::AddExternal( const OUString& rStr,
 
 FormulaToken* FormulaTokenArray::AddBad( const OUString& rStr )
 {
-    return Add( new FormulaStringOpToken( ocBad, rStr ) );
+    return Add( new FormulaStringOpToken( ocBad, svl::SharedString( rStr ) ) ); // string not interned
 }
 
 FormulaToken* FormulaTokenArray::AddStringXML( const OUString& rStr )
 {
-    return Add( new FormulaStringOpToken( ocStringXML, rStr ) );
+    return Add( new FormulaStringOpToken( ocStringXML, svl::SharedString( rStr ) ) );   // string not interned
 }
 
 
diff --git a/include/svl/sharedstring.hxx b/include/svl/sharedstring.hxx
index fe9e851..1693c63 100644
--- a/include/svl/sharedstring.hxx
+++ b/include/svl/sharedstring.hxx
@@ -25,7 +25,7 @@ public:
 
     SharedString();
     SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase );
-    SharedString( const OUString& rStr );
+    explicit SharedString( const OUString& rStr );
     SharedString( const SharedString& r );
     ~SharedString();
 
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index 7606431..061d044 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -98,9 +98,9 @@ public:
     formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
     void                   AddRangeName( sal_uInt16 n, sal_Int16 nSheet );
     formula::FormulaToken* AddDBRange( sal_uInt16 n );
-    formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const OUString& rName );
-    void AddExternalSingleReference( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef );
-    formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef );
+    formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName );
+    void AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScSingleRefData& rRef );
+    formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScComplexRefData& rRef );
     formula::FormulaToken* AddMatrix( const ScMatrixRef& p );
     /** ScSingleRefOpToken with ocColRowName. */
     formula::FormulaToken* AddColRowName( const ScSingleRefData& rRef );
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index a32b2f7..eccb7dc 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2026,13 +2026,14 @@ formula::FormulaTokenRef ScColumn::ResolveStaticReference( SCROW nRow )
         case sc::element_type_string:
         {
             const svl::SharedString& rSS = sc::string_block::at(*it->data, aPos.second);
-            return formula::FormulaTokenRef(new formula::FormulaStringToken(rSS.getString()));
+            return formula::FormulaTokenRef(new formula::FormulaStringToken(rSS));
         }
         case sc::element_type_edittext:
         {
             const EditTextObject* pText = sc::edittext_block::at(*it->data, aPos.second);
             OUString aStr = ScEditUtil::GetString(*pText, pDocument);
-            return formula::FormulaTokenRef(new formula::FormulaStringToken(aStr));
+            svl::SharedString aSS( pDocument->GetSharedStringPool().intern(aStr));
+            return formula::FormulaTokenRef(new formula::FormulaStringToken(aSS));
         }
         case sc::element_type_empty:
         default:
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index b573544..df2755f 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -125,7 +125,7 @@ svl::SharedString ScSimpleFormulaCalculator::GetString()
     Calculate();
 
     if (mbMatrixResult)
-        return maMatrixFormulaResult;
+        return svl::SharedString( maMatrixFormulaResult);   // string not interned
 
     if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == formula::errDoubleRef) &&
             !maResult.GetResultError())
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index bb1ad0e..6e78b88 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -2356,7 +2356,7 @@ void ScInterpreter::ScCellExternal()
     {
         // ODF 1.2 says we need to always display address using the ODF A1 grammar.
         ScTokenArray aArray;
-        aArray.AddExternalSingleReference(nFileId, aTabName, aRef);
+        aArray.AddExternalSingleReference(nFileId, svl::SharedString( aTabName), aRef); // string not interned
         ScCompiler aComp(pDok, aPos, aArray);
         aComp.SetGrammar(formula::FormulaGrammar::GRAM_ODFF_A1);
         OUString aStr;
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 343cb90..eff2871 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -1737,7 +1737,8 @@ void ScInterpreter::PushExternalSingleRef(
     {
         ScSingleRefData aRef;
         aRef.InitAddress(ScAddress(nCol,nRow,nTab));
-        PushTempTokenWithoutError( new ScExternalSingleRefToken(nFileId, rTabName, aRef)) ;
+        PushTempTokenWithoutError( new ScExternalSingleRefToken(nFileId,
+                    pDok->GetSharedStringPool().intern( rTabName), aRef)) ;
     }
 }
 
@@ -1749,7 +1750,8 @@ void ScInterpreter::PushExternalDoubleRef(
     {
         ScComplexRefData aRef;
         aRef.InitRange(ScRange(nCol1,nRow1,nTab1,nCol2,nRow2,nTab2));
-        PushTempTokenWithoutError( new ScExternalDoubleRefToken(nFileId, rTabName, aRef) );
+        PushTempTokenWithoutError( new ScExternalDoubleRefToken(nFileId,
+                    pDok->GetSharedStringPool().intern( rTabName), aRef) );
     }
 }
 
diff --git a/sc/source/core/tool/reftokenhelper.cxx b/sc/source/core/tool/reftokenhelper.cxx
index 70b2faa..8e90b03 100644
--- a/sc/source/core/tool/reftokenhelper.cxx
+++ b/sc/source/core/tool/reftokenhelper.cxx
@@ -321,7 +321,7 @@ private:
         // Get the information of the new token.
         bool bExternal = ScRefTokenHelper::isExternalRef(pToken);
         sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0;
-        OUString aTabName = bExternal ? pToken->GetString().getString() : OUString();
+        svl::SharedString aTabName = bExternal ? pToken->GetString() : svl::SharedString::getEmptyString();
 
         bool bJoined = false;
         vector<ScTokenRef>::iterator itr = rTokens.begin(), itrEnd = rTokens.end();
@@ -344,7 +344,7 @@ private:
                     // Different external files.
                     continue;
 
-                if (aTabName != pOldToken->GetString().getString())
+                if (aTabName != pOldToken->GetString())
                     // Different table names.
                     continue;
             }
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 4aa0993..a693aba 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -600,7 +600,7 @@ svl::SharedString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE
     if (!ValidColRowOrReplicated( nC, nR ))
     {
         OSL_FAIL("ScMatrixImpl::GetString: dimension error");
-        return OUString();
+        return svl::SharedString::getEmptyString();
     }
 
     double fVal = 0.0;
@@ -608,7 +608,7 @@ svl::SharedString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE
     switch (maMat.get_type(aPos))
     {
         case mdds::mtm::element_string:
-            return maMat.get_string(aPos).getString();
+            return maMat.get_string(aPos);
         case mdds::mtm::element_empty:
         {
             if (maMatFlag.get_numeric(nR, nC) != SC_MATFLAG_EMPTYPATH)
@@ -621,7 +621,7 @@ svl::SharedString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE
             OUString aStr;
             Color* pColor = nullptr;
             rFormatter.GetOutputString( 0.0, nKey, aStr, &pColor);
-            return aStr;
+            return svl::SharedString( aStr);    // string not interned
         }
         case mdds::mtm::element_numeric:
         case mdds::mtm::element_boolean:
@@ -635,14 +635,14 @@ svl::SharedString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE
     if (nError)
     {
         SetErrorAtInterpreter( nError);
-        return ScGlobal::GetErrorString( nError);
+        return svl::SharedString( ScGlobal::GetErrorString( nError));   // string not interned
     }
 
     sal_uLong nKey = rFormatter.GetStandardFormat( css::util::NumberFormat::NUMBER,
             ScGlobal::eLnge);
     OUString aStr;
     rFormatter.GetInputLineString( fVal, nKey, aStr);
-    return aStr;
+    return svl::SharedString( aStr);    // string not interned
 }
 
 ScMatrixValue ScMatrixImpl::Get(SCSIZE nC, SCSIZE nR) const
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index d9c2505..c7f03f2 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -418,17 +418,17 @@ FormulaToken* ScRawToken::CreateToken() const
                 return new FormulaIndexToken( eOp, name.nIndex, name.nSheet);
         case svExternalSingleRef:
             {
-                OUString aTabName(extref.cTabName);
+                svl::SharedString aTabName( OUString( extref.cTabName));    // string not interned
                 return new ScExternalSingleRefToken(extref.nFileId, aTabName, extref.aRef.Ref1);
             }
         case svExternalDoubleRef:
             {
-                OUString aTabName(extref.cTabName);
+                svl::SharedString aTabName( OUString( extref.cTabName));    // string not interned
                 return new ScExternalDoubleRefToken(extref.nFileId, aTabName, extref.aRef);
             }
         case svExternalName:
             {
-                OUString aName(extname.cName);
+                svl::SharedString aName( OUString( extname.cName));         // string not interned
                 return new ScExternalNameToken( extname.nFileId, aName );
             }
         case svJump :
@@ -1251,7 +1251,7 @@ bool ScTokenArray::AddFormulaToken(
                                     ScSingleRefData aSingleRef;
                                     // convert column/row settings, set sheet index to absolute
                                     lcl_ExternalRefToCalc( aSingleRef, aApiSRef );
-                                    AddExternalSingleReference( nFileId, aTabName, aSingleRef );
+                                    AddExternalSingleReference( nFileId, rSPool.intern( aTabName), aSingleRef );
                                 }
                                 else
                                     bError = true;
@@ -1270,7 +1270,7 @@ bool ScTokenArray::AddFormulaToken(
                                     // NOTE: This assumes that cached sheets are in consecutive order!
                                     aComplRef.Ref2.SetAbsTab(
                                         aComplRef.Ref1.Tab() + static_cast<SCTAB>(aApiCRef.Reference2.Sheet - aApiCRef.Reference1.Sheet));
-                                    AddExternalDoubleReference( nFileId, aTabName, aComplRef );
+                                    AddExternalDoubleReference( nFileId, rSPool.intern( aTabName), aComplRef );
                                 }
                                 else
                                     bError = true;
@@ -1278,7 +1278,7 @@ bool ScTokenArray::AddFormulaToken(
                             else if( aApiExtRef.Reference >>= aName )
                             {
                                 if( !aName.isEmpty() )
-                                    AddExternalName( nFileId, aName );
+                                    AddExternalName( nFileId, rSPool.intern( aName) );
                                 else
                                     bError = true;
                             }
@@ -2080,17 +2080,19 @@ FormulaToken* ScTokenArray::AddDBRange( sal_uInt16 n )
     return Add( new FormulaIndexToken( ocDBArea, n));
 }
 
-FormulaToken* ScTokenArray::AddExternalName( sal_uInt16 nFileId, const OUString& rName )
+FormulaToken* ScTokenArray::AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName )
 {
     return Add( new ScExternalNameToken(nFileId, rName) );
 }
 
-void ScTokenArray::AddExternalSingleReference( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef )
+void ScTokenArray::AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName,
+        const ScSingleRefData& rRef )
 {
     Add( new ScExternalSingleRefToken(nFileId, rTabName, rRef) );
 }
 
-FormulaToken* ScTokenArray::AddExternalDoubleReference( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef )
+FormulaToken* ScTokenArray::AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName,
+        const ScComplexRefData& rRef )
 {
     return Add( new ScExternalDoubleRefToken(nFileId, rTabName, rRef) );
 }
@@ -2105,9 +2107,10 @@ void ScTokenArray::AssignXMLString( const OUString &rText, const OUString &rForm
     sal_uInt16 nTokens = 1;
     FormulaToken *aTokens[2];
 
-    aTokens[0] = new FormulaStringOpToken( ocStringXML, rText );
+    aTokens[0] = new FormulaStringOpToken( ocStringXML, svl::SharedString( rText) );    // string not interned
     if( !rFormulaNmsp.isEmpty() )
-        aTokens[ nTokens++ ] = new FormulaStringOpToken( ocStringXML, rFormulaNmsp );
+        aTokens[ nTokens++ ] = new FormulaStringOpToken( ocStringXML,
+                svl::SharedString( rFormulaNmsp) );   // string not interned
 
     Assign( nTokens, aTokens );
 }
@@ -2400,7 +2403,8 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons
                     OUString aTabName;
                     sal_uInt16 nFileId;
                     GetExternalTableData(pOldDoc, pNewDoc, rRef1.Tab(), aTabName, nFileId);
-                    ReplaceToken( j, new ScExternalDoubleRefToken(nFileId, aTabName, rRef), CODE_AND_RPN);
+                    ReplaceToken( j, new ScExternalDoubleRefToken(nFileId, svl::SharedString( aTabName), rRef),
+                            CODE_AND_RPN);  // string not interned (pNewDoc would have to be non-const)
                     // ATTENTION: rRef can't be used after this point
                 }
             }
@@ -2417,7 +2421,8 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons
                     OUString aTabName;
                     sal_uInt16 nFileId;
                     GetExternalTableData(pOldDoc, pNewDoc, rRef.Tab(), aTabName, nFileId);
-                    ReplaceToken( j, new ScExternalSingleRefToken(nFileId, aTabName, rRef), CODE_AND_RPN);
+                    ReplaceToken( j, new ScExternalSingleRefToken(nFileId, svl::SharedString( aTabName), rRef),
+                            CODE_AND_RPN);  // string not interned (pNewDoc would have to be non-const)
                     // ATTENTION: rRef can't be used after this point
                 }
             }
diff --git a/sc/source/filter/excel/tokstack.cxx b/sc/source/filter/excel/tokstack.cxx
index 9323f93..edd2289 100644
--- a/sc/source/filter/excel/tokstack.cxx
+++ b/sc/source/filter/excel/tokstack.cxx
@@ -473,7 +473,7 @@ bool TokenPool::GetElement( const sal_uInt16 nId )
                 if (n < maExtNames.size())
                 {
                     const ExtName& r = maExtNames[n];
-                    pScToken->AddExternalName(r.mnFileId, r.maName);
+                    pScToken->AddExternalName(r.mnFileId, svl::SharedString( r.maName));    // string not interned
                 }
                 else
                     bRet = false;
@@ -485,7 +485,8 @@ bool TokenPool::GetElement( const sal_uInt16 nId )
                 if (n < maExtCellRefs.size())
                 {
                     const ExtCellRef& r = maExtCellRefs[n];
-                    pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
+                    pScToken->AddExternalSingleReference(r.mnFileId, svl::SharedString( r.maTabName),
+                            r.maRef); // string not interned
                 }
                 else
                     bRet = false;
@@ -497,7 +498,8 @@ bool TokenPool::GetElement( const sal_uInt16 nId )
                 if (n < maExtAreaRefs.size())
                 {
                     const ExtAreaRef& r = maExtAreaRefs[n];
-                    pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
+                    pScToken->AddExternalDoubleReference(r.mnFileId, svl::SharedString( r.maTabName),
+                            r.maRef);   // string not interned
                 }
                 else
                     bRet = false;
diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx
index 6e98086..2b2c3a6 100644
--- a/sc/source/filter/excel/xechart.cxx
+++ b/sc/source/filter/excel/xechart.cxx
@@ -871,7 +871,7 @@ void lclAddDoubleRefData(
         "lclAddDoubleRefData - double reference token expected");
     if( rToken.GetType() == ::formula::svExternalDoubleRef )
         orArray.AddExternalDoubleReference(
-            rToken.GetIndex(), rToken.GetString().getString(), aComplexRef);
+            rToken.GetIndex(), rToken.GetString(), aComplexRef);
     else
         orArray.AddDoubleReference( aComplexRef );
 }
diff --git a/sc/source/filter/excel/xilink.cxx b/sc/source/filter/excel/xilink.cxx
index 467cc99..f527b8b 100644
--- a/sc/source/filter/excel/xilink.cxx
+++ b/sc/source/filter/excel/xilink.cxx
@@ -609,7 +609,7 @@ void XclImpSupbookTab::LoadCachedValues(const ScExternalRefCache::TableTypeRef&
             case EXC_CACHEDVAL_STRING:
             {
                 const OUString& rStr = pCrn->GetString();
-                ScExternalRefCache::TokenRef pToken(new formula::FormulaStringToken(rStr));
+                ScExternalRefCache::TokenRef pToken(new formula::FormulaStringToken( svl::SharedString( rStr)));    // string not interned
                 pCacheTable->setCell(rAddr.mnCol, rAddr.mnRow, pToken, 0, false);
             }
             break;
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index eac311d..149435e 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1444,7 +1444,8 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
                         if (!IsPossibleErrorString())
                         {
                             pFCell->SetResultMatrix(
-                                nMatrixCols, nMatrixRows, pMat, new formula::FormulaStringToken(*maStringValue));
+                                    nMatrixCols, nMatrixRows, pMat, new formula::FormulaStringToken(
+                                        rXMLImport.GetDocument()->GetSharedStringPool().intern( *maStringValue)));
                             pFCell->ResetDirty();
                         }
                     }
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index f703b67..d97d547 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2342,7 +2342,8 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getRangeNameTokensFromSr
                 const ScSingleRefData& rRef = *pToken->GetSingleRef();
                 OUString aTabName;
                 pSrcDoc->GetName(rRef.Tab(), aTabName);
-                ScExternalSingleRefToken aNewToken(nFileId, aTabName, *pToken->GetSingleRef());
+                ScExternalSingleRefToken aNewToken(nFileId, svl::SharedString( aTabName),   // string not interned
+                        *pToken->GetSingleRef());
                 pNew->AddToken(aNewToken);
                 bTokenAdded = true;
             }
@@ -2352,7 +2353,8 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getRangeNameTokensFromSr
                 const ScSingleRefData& rRef = *pToken->GetSingleRef();
                 OUString aTabName;
                 pSrcDoc->GetName(rRef.Tab(), aTabName);
-                ScExternalDoubleRefToken aNewToken(nFileId, aTabName, *pToken->GetDoubleRef());
+                ScExternalDoubleRefToken aNewToken(nFileId, svl::SharedString( aTabName),   // string not interned
+                        *pToken->GetDoubleRef());
                 pNew->AddToken(aNewToken);
                 bTokenAdded = true;
             }


More information about the Libreoffice-commits mailing list