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

Kohei Yoshida kohei.yoshida at collabora.com
Thu Jun 1 13:32:54 UTC 2017


 sc/inc/dpcache.hxx                 |    4 ++--
 sc/inc/dpitemdata.hxx              |    6 +++---
 sc/source/core/data/dpcache.cxx    |   10 +++++-----
 sc/source/core/data/dpitemdata.cxx |   31 +++++++++++++++++++------------
 sc/source/core/data/dpobject.cxx   |    2 +-
 5 files changed, 30 insertions(+), 23 deletions(-)

New commits:
commit 5ecb3f4625188d02e85a3daef76ccf7f26b33a61
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 30 20:14:15 2017 -0400

    tdf#107945: store rtl_uString pointers instead of heap OUString objects.
    
    Change-Id: I61079e041a79195f9e9cb77ce80368ef7e909cef
    Reviewed-on: https://gerrit.libreoffice.org/38288
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/inc/dpcache.hxx b/sc/inc/dpcache.hxx
index 60a23002b770..515a3fae6a19 100644
--- a/sc/inc/dpcache.hxx
+++ b/sc/inc/dpcache.hxx
@@ -117,7 +117,7 @@ private:
 
     FieldsType maFields;
     GroupFieldsType maGroupFields;
-    mutable StringSetType maStringPool;
+    StringSetType maStringPool;
 
     std::vector<OUString> maLabelNames; // Stores dimension names and the data layout dimension name at position 0.
     mdds::flat_segment_tree<SCROW, bool> maEmptyRows;
@@ -127,7 +127,7 @@ private:
     bool mbDisposing;
 
 public:
-    const OUString* InternString(const OUString& rStr) const;
+    rtl_uString* InternString( const OUString& rStr );
     void AddReference(ScDPObject* pObj) const;
     void RemoveReference(ScDPObject* pObj) const;
     const ScDPObjectSet& GetAllReferences() const;
diff --git a/sc/inc/dpitemdata.hxx b/sc/inc/dpitemdata.hxx
index 224421058fa0..44e3dc1930c1 100644
--- a/sc/inc/dpitemdata.hxx
+++ b/sc/inc/dpitemdata.hxx
@@ -45,7 +45,7 @@ public:
 private:
 
     union {
-        const OUString* mpString;
+        rtl_uString* mpString;
         GroupValueAttr maGroupValue;
         double mfValue;
     };
@@ -68,12 +68,12 @@ public:
     Type GetType() const { return static_cast<Type>(meType); }
     void SetEmpty();
     void SetString(const OUString& rS);
-    void SetString(const OUString* pS);
+    void SetStringInterned( rtl_uString* pS );
     void SetValue(double fVal);
     void SetRangeStart(double fVal);
     void SetRangeFirst();
     void SetRangeLast();
-    void SetErrorString(const OUString* pS);
+    void SetErrorStringInterned( rtl_uString* pS );
     bool IsCaseInsEqual(const ScDPItemData& r) const;
 
     // exact equality
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index b65cdaae1bad..0383108bf81b 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -134,7 +134,7 @@ void initFromCell(
 
     if (rCell.hasError())
     {
-        rData.SetErrorString(rCache.InternString(aDocStr));
+        rData.SetErrorStringInterned(rCache.InternString(aDocStr));
     }
     else if (rCell.hasNumeric())
     {
@@ -144,7 +144,7 @@ void initFromCell(
     }
     else if (!rCell.isEmpty())
     {
-        rData.SetString(rCache.InternString(aDocStr));
+        rData.SetStringInterned(rCache.InternString(aDocStr));
     }
     else
         rData.SetEmpty();
@@ -901,15 +901,15 @@ SCCOL ScDPCache::GetDimensionIndex(const OUString& sName) const
     return -1;
 }
 
-const OUString* ScDPCache::InternString(const OUString& rStr) const
+rtl_uString* ScDPCache::InternString( const OUString& rStr )
 {
     StringSetType::iterator it = maStringPool.find(rStr);
     if (it != maStringPool.end())
         // In the pool.
-        return &(*it);
+        return (*it).pData;
 
     std::pair<StringSetType::iterator, bool> r = maStringPool.insert(rStr);
-    return r.second ? &(*r.first) : nullptr;
+    return r.second ? (*r.first).pData : nullptr;
 }
 
 void ScDPCache::AddReference(ScDPObject* pObj) const
diff --git a/sc/source/core/data/dpitemdata.cxx b/sc/source/core/data/dpitemdata.cxx
index fa8021f62d4a..0fd3357c4c9e 100644
--- a/sc/source/core/data/dpitemdata.cxx
+++ b/sc/source/core/data/dpitemdata.cxx
@@ -83,7 +83,9 @@ ScDPItemData::ScDPItemData(const ScDPItemData& r) :
     {
         case String:
         case Error:
-            mpString = mbStringInterned ? r.mpString :  new OUString(*r.mpString);
+            mpString = r.mpString;
+            if (!mbStringInterned)
+                rtl_uString_acquire(mpString);
         break;
         case Value:
         case RangeStart:
@@ -104,14 +106,17 @@ void ScDPItemData::DisposeString()
     if (!mbStringInterned)
     {
         if (meType == String || meType == Error)
-            delete mpString;
+            rtl_uString_release(mpString);
     }
 
     mbStringInterned = false;
 }
 
 ScDPItemData::ScDPItemData(const OUString& rStr) :
-    mpString(new OUString(rStr)), meType(String), mbStringInterned(false) {}
+    mpString(rStr.pData), meType(String), mbStringInterned(false)
+{
+    rtl_uString_acquire(mpString);
+}
 
 ScDPItemData::ScDPItemData(sal_Int32 nGroupType, sal_Int32 nValue) :
     meType(GroupValue), mbStringInterned(false)
@@ -134,11 +139,12 @@ void ScDPItemData::SetEmpty()
 void ScDPItemData::SetString(const OUString& rS)
 {
     DisposeString();
-    mpString = new OUString(rS);
+    mpString = rS.pData;
+    rtl_uString_acquire(mpString);
     meType = String;
 }
 
-void ScDPItemData::SetString(const OUString* pS)
+void ScDPItemData::SetStringInterned( rtl_uString* pS )
 {
     DisposeString();
     mpString = pS;
@@ -174,9 +180,9 @@ void ScDPItemData::SetRangeLast()
     meType = RangeStart;
 }
 
-void ScDPItemData::SetErrorString(const OUString* pS)
+void ScDPItemData::SetErrorStringInterned( rtl_uString* pS )
 {
-    SetString(pS);
+    SetStringInterned(pS);
     meType = Error;
 }
 
@@ -234,13 +240,14 @@ ScDPItemData& ScDPItemData::operator= (const ScDPItemData& r)
 {
     DisposeString();
     meType = r.meType;
-    mbStringInterned = false;
     switch (r.meType)
     {
         case String:
         case Error:
-            mpString = r.mbStringInterned ? r.mpString : new OUString(*r.mpString);
             mbStringInterned = r.mbStringInterned;
+            mpString = r.mpString;
+            if (!mbStringInterned)
+                rtl_uString_acquire(mpString);
         break;
         case Value:
         case RangeStart:
@@ -286,7 +293,7 @@ void ScDPItemData::Dump(const char* msg) const
         break;
         case Error:
             printf("error: %s\n",
-                   OUStringToOString(*mpString, RTL_TEXTENCODING_UTF8).getStr());
+                   OUStringToOString(OUString(mpString), RTL_TEXTENCODING_UTF8).getStr());
         break;
         case GroupValue:
             printf("group value: group type = %d  value = %d\n",
@@ -294,7 +301,7 @@ void ScDPItemData::Dump(const char* msg) const
         break;
         case String:
             printf("string: %s\n",
-                   OUStringToOString(*mpString, RTL_TEXTENCODING_UTF8).getStr());
+                   OUStringToOString(OUString(mpString), RTL_TEXTENCODING_UTF8).getStr());
         break;
         case Value:
             printf("value: %g\n", mfValue);
@@ -325,7 +332,7 @@ OUString ScDPItemData::GetString() const
     {
         case String:
         case Error:
-            return *mpString;
+            return OUString(mpString);
         case Value:
         case RangeStart:
             return OUString::number(mfValue);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 28779f3238a3..19dc7e846d6d 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -247,7 +247,7 @@ void DBConnector::getValue(long nCol, ScDPItemData &rData, short& rNumType) cons
             case sdbc::DataType::VARBINARY:
             case sdbc::DataType::LONGVARBINARY:
             default:
-                rData.SetString(mrCache.InternString(mxRow->getString(nCol+1)));
+                rData.SetStringInterned(mrCache.InternString(mxRow->getString(nCol+1)));
         }
     }
     catch (uno::Exception&)


More information about the Libreoffice-commits mailing list