[Libreoffice-commits] core.git: Branch 'private/kohei/calc-shared-string' - include/svl svl/qa svl/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Oct 2 09:19:00 PDT 2013


 include/svl/stringpool.hxx     |    6 ++++--
 svl/qa/unit/svl.cxx            |   39 +++++++++++++++++++++------------------
 svl/source/misc/stringpool.cxx |   10 +++++-----
 3 files changed, 30 insertions(+), 25 deletions(-)

New commits:
commit 5bedbfd89540d6c81e38716144c4ec5e873e98c7
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Oct 2 12:19:19 2013 -0400

    Let's not expose the internal pointer. Define different ID type.
    
    To prevent the string ID's from being used to instantiate string objects,
    which can mess up shared string object's life cycles.
    
    Change-Id: Ibcd9a4fa9f591d5c27a9e1b50bc9f83ae230e86a

diff --git a/include/svl/stringpool.hxx b/include/svl/stringpool.hxx
index 26785e3..4436efe 100644
--- a/include/svl/stringpool.hxx
+++ b/include/svl/stringpool.hxx
@@ -37,6 +37,8 @@ class SVL_DLLPUBLIC StringPool
     const CharClass* mpCharClass;
 
 public:
+    typedef sal_uIntPtr StrIdType;
+
     StringPool();
     StringPool( const CharClass* pCharClass );
 
@@ -58,9 +60,9 @@ public:
      *
      * @return unique ID of the string object.
      */
-    const rtl_uString* getIdentifier( const OUString& rStr ) const;
+    StrIdType getIdentifier( const OUString& rStr ) const;
 
-    const rtl_uString* getIdentifierIgnoreCase( const OUString& rStr ) const;
+    StrIdType getIdentifierIgnoreCase( const OUString& rStr ) const;
 
 private:
     InsertResultType findOrInsert( StrHashType& rPool, const OUString& rStr ) const;
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index f41ab73..003a152 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -305,27 +305,30 @@ void Test::testStringPool()
     CPPUNIT_ASSERT_MESSAGE("They must differ.", p1 != p2);
 
     OUString aAndy("Andy");
-    p2 = aPool.getIdentifier(aAndy);
-    CPPUNIT_ASSERT_EQUAL(p1, p2);
+    svl::StringPool::StrIdType si1 = aPool.getIdentifier("Andy");
+    svl::StringPool::StrIdType si2 = aPool.getIdentifier(aAndy);
+    CPPUNIT_ASSERT_EQUAL(si1, si2);
 
     // Test case insensitive string ID's.
     OUString aAndyLower("andy"), aAndyUpper("ANDY");
-    p1 = aPool.getIdentifier("Andy");
-    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p1);
-    p2 = aPool.intern(aAndyLower);
-    CPPUNIT_ASSERT_MESSAGE("They must differ.", p1 != p2);
-    p2 = aPool.intern(aAndyUpper);
-    CPPUNIT_ASSERT_MESSAGE("They must differ.", p1 != p2);
-
-    p1 = aPool.getIdentifierIgnoreCase("Andy");
-    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p1);
-    p2 = aPool.getIdentifierIgnoreCase("andy");
-    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p2);
-    CPPUNIT_ASSERT_EQUAL(p1, p2);
-
-    p2 = aPool.getIdentifierIgnoreCase("ANDY");
-    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p2);
-    CPPUNIT_ASSERT_EQUAL(p1, p2);
+    si1 = aPool.getIdentifier("Andy");
+    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", si1);
+    aPool.intern(aAndyLower);
+    si2 = aPool.getIdentifier(aAndyLower);
+    CPPUNIT_ASSERT_MESSAGE("They must differ.", si1 != si2);
+    aPool.intern(aAndyUpper);
+    si2 = aPool.getIdentifier(aAndyUpper);
+    CPPUNIT_ASSERT_MESSAGE("They must differ.", si1 != si2);
+
+    si1 = aPool.getIdentifierIgnoreCase("Andy");
+    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", si1);
+    si2 = aPool.getIdentifierIgnoreCase("andy");
+    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", si2);
+    CPPUNIT_ASSERT_EQUAL(si1, si2);
+
+    si2 = aPool.getIdentifierIgnoreCase("ANDY");
+    CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", si2);
+    CPPUNIT_ASSERT_EQUAL(si1, si2);
 }
 
 void Test::checkPreviewString(SvNumberFormatter& aFormatter,
diff --git a/svl/source/misc/stringpool.cxx b/svl/source/misc/stringpool.cxx
index 1181538..c0030fe 100644
--- a/svl/source/misc/stringpool.cxx
+++ b/svl/source/misc/stringpool.cxx
@@ -46,20 +46,20 @@ rtl_uString* StringPool::intern( const OUString& rStr )
     return pOrig;
 }
 
-const rtl_uString* StringPool::getIdentifier( const OUString& rStr ) const
+StringPool::StrIdType StringPool::getIdentifier( const OUString& rStr ) const
 {
     StrHashType::iterator it = maStrPool.find(rStr);
-    return (it == maStrPool.end()) ? NULL : it->pData;
+    return (it == maStrPool.end()) ? 0 : reinterpret_cast<StrIdType>(it->pData);
 }
 
-const rtl_uString* StringPool::getIdentifierIgnoreCase( const OUString& rStr ) const
+StringPool::StrIdType StringPool::getIdentifierIgnoreCase( const OUString& rStr ) const
 {
     if (!mpCharClass)
-        return NULL;
+        return 0;
 
     OUString aUpper = mpCharClass->uppercase(rStr);
     StrHashType::iterator it = maStrPoolUpper.find(aUpper);
-    return (it == maStrPool.end()) ? NULL : it->pData;
+    return (it == maStrPool.end()) ? 0 : reinterpret_cast<StrIdType>(it->pData);
 }
 
 StringPool::InsertResultType StringPool::findOrInsert( StrHashType& rPool, const OUString& rStr ) const


More information about the Libreoffice-commits mailing list