No more getIdentifier*() calls because they are not efficient.

They shall never be used.

Change-Id: I019c88b1511a67175d782777cd41e0ec0434f497
This commit is contained in:
Kohei Yoshida
2013-10-08 15:48:12 -04:00
parent a7ff6e0a3f
commit 3786609a15
15 changed files with 82 additions and 204 deletions
+9 -46
View File
@@ -154,16 +154,9 @@ void ContentInfo::NormalizeString( svl::SharedStringPool& rPool )
maText = rPool.intern(OUString(maText.getData()));
}
sal_uIntPtr ContentInfo::GetStringID( const svl::SharedStringPool& rPool ) const
const svl::SharedString& ContentInfo::GetSharedString() const
{
rtl_uString* p = const_cast<rtl_uString*>(maText.getData());
return rPool.getIdentifier(OUString(p));
}
sal_uIntPtr ContentInfo::GetStringIDIgnoreCase( const svl::SharedStringPool& rPool ) const
{
rtl_uString* p = const_cast<rtl_uString*>(maText.getData());
return rPool.getIdentifierIgnoreCase(OUString(p));
return maText;
}
OUString ContentInfo::GetText() const
@@ -350,14 +343,9 @@ void EditTextObject::NormalizeString( svl::SharedStringPool& rPool )
mpImpl->NormalizeString(rPool);
}
bool EditTextObject::GetStringIDs( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const
std::vector<svl::SharedString> EditTextObject::GetSharedStrings() const
{
return mpImpl->GetStringIDs(rPool, rIDs);
}
bool EditTextObject::GetStringIDsIgnoreCase( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const
{
return mpImpl->GetStringIDsIgnoreCase(rPool, rIDs);
return mpImpl->GetSharedStrings();
}
const SfxItemPool* EditTextObject::GetPool() const
@@ -656,42 +644,17 @@ void EditTextObjectImpl::NormalizeString( svl::SharedStringPool& rPool )
}
}
bool EditTextObjectImpl::GetStringIDs( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const
std::vector<svl::SharedString> EditTextObjectImpl::GetSharedStrings() const
{
std::vector<sal_uIntPtr> aIDs;
aIDs.reserve(aContents.size());
std::vector<svl::SharedString> aSSs;
aSSs.reserve(aContents.size());
ContentInfosType::const_iterator it = aContents.begin(), itEnd = aContents.end();
for (; it != itEnd; ++it)
{
const ContentInfo& rInfo = *it;
sal_uIntPtr nID = rInfo.GetStringID(rPool);
if (!nID)
return false;
aIDs.push_back(nID);
aSSs.push_back(rInfo.GetSharedString());
}
rIDs.swap(aIDs);
return true;
}
bool EditTextObjectImpl::GetStringIDsIgnoreCase( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const
{
std::vector<sal_uIntPtr> aIDs;
aIDs.reserve(aContents.size());
ContentInfosType::const_iterator it = aContents.begin(), itEnd = aContents.end();
for (; it != itEnd; ++it)
{
const ContentInfo& rInfo = *it;
sal_uIntPtr nID = rInfo.GetStringIDIgnoreCase(rPool);
if (!nID)
return false;
aIDs.push_back(nID);
}
rIDs.swap(aIDs);
return true;
return aSSs;
}
bool EditTextObjectImpl::IsVertical() const
+2 -4
View File
@@ -144,8 +144,7 @@ public:
~ContentInfo();
void NormalizeString( svl::SharedStringPool& rPool );
sal_uIntPtr GetStringID( const svl::SharedStringPool& rPool ) const;
sal_uIntPtr GetStringIDIgnoreCase( const svl::SharedStringPool& rPool ) const;
const svl::SharedString& GetSharedString() const;
OUString GetText() const;
void SetText( const OUString& rStr );
@@ -210,8 +209,7 @@ public:
void SetUserType( sal_uInt16 n );
void NormalizeString( svl::SharedStringPool& rPool );
bool GetStringIDs( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const;
bool GetStringIDsIgnoreCase( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const;
std::vector<svl::SharedString> GetSharedStrings() const;
bool IsVertical() const;
void SetVertical( bool b );
+2 -2
View File
@@ -51,6 +51,7 @@ struct Section;
namespace svl {
class SharedString;
class SharedStringPool;
}
@@ -85,8 +86,7 @@ public:
*/
void NormalizeString( svl::SharedStringPool& rPool );
bool GetStringIDs( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const;
bool GetStringIDsIgnoreCase( const svl::SharedStringPool& rPool, std::vector<sal_uIntPtr>& rIDs ) const;
std::vector<svl::SharedString> GetSharedStrings() const;
const SfxItemPool* GetPool() const;
sal_uInt16 GetUserType() const; // For OutlinerMode, it can however not save in compatible format
+3
View File
@@ -29,6 +29,7 @@ public:
SharedString& operator= ( const SharedString& r );
bool operator== ( const SharedString& r ) const;
bool operator!= ( const SharedString& r ) const;
OUString getString() const;
@@ -37,6 +38,8 @@ public:
rtl_uString* getDataIgnoreCase();
const rtl_uString* getDataIgnoreCase() const;
bool isValid() const;
};
}
-22
View File
@@ -50,28 +50,6 @@ public:
*/
SharedString intern( const OUString& rStr );
/**
* Get a unique ID of string object that's expected to be in the shared
* string pool. If the string is not in the pool, NULL is returned. The
* ID obtained by this method can be used for case sensitive comparison.
*
* @param rStr string object to get the ID of.
*
* @return unique ID of the string object.
*/
sal_uIntPtr getIdentifier( const OUString& rStr ) const;
/**
* Get a unique ID of string object for case insensitive comparison. The
* string object is expected to be in the pool.
*
* @param rStr string object to get the ID of.
*
* @return unique ID of the string object usable for case insensitive
* comparison.
*/
sal_uIntPtr getIdentifierIgnoreCase( const OUString& rStr ) const;
/**
* Go through all string objects in the pool, and clear those that are no
* longer used outside of the pool.
+1 -2
View File
@@ -280,8 +280,7 @@ public:
ScFormulaCell* SetFormulaCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScFormulaCell* pCell );
bool SetGroupFormulaCell( SCROW nRow, ScFormulaCell* pCell );
sal_uIntPtr GetCellStringID( SCROW nRow ) const;
sal_uIntPtr GetCellStringIDIgnoreCase( SCROW nRow ) const;
svl::SharedString GetSharedString( SCROW nRow ) const;
void SetRawString( SCROW nRow, const OUString& rStr, bool bBroadcast = true );
void SetRawString( SCROW nRow, const svl::SharedString& rStr, bool bBroadcast = true );
+2 -2
View File
@@ -855,8 +855,8 @@ public:
SC_DLLPUBLIC svl::SharedStringPool& GetSharedStringPool();
const svl::SharedStringPool& GetSharedStringPool() const;
sal_uIntPtr GetCellStringID( const ScAddress& rPos ) const;
sal_uIntPtr GetCellStringIDIgnoreCase( const ScAddress& rPos ) const;
svl::SharedString GetSharedString( const ScAddress& rPos ) const;
SC_DLLPUBLIC void GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rString );
SC_DLLPUBLIC void GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rString );
+1 -2
View File
@@ -343,8 +343,7 @@ public:
ScFormulaCell* SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );
bool SetGroupFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );
sal_uIntPtr GetCellStringID( SCCOL nCol, SCROW nRow ) const;
sal_uIntPtr GetCellStringIDIgnoreCase( SCCOL nCol, SCROW nRow ) const;
svl::SharedString GetSharedString( SCCOL nCol, SCROW nRow ) const;
void SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
void SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError);
+37 -37
View File
@@ -461,7 +461,7 @@ void Test::testCollator()
CPPUNIT_ASSERT_MESSAGE("these strings are supposed to be different!", nRes != 0);
}
void Test::testCellStringPool()
void Test::testSharedStringPool()
{
m_pDoc->InsertTab(0, "foo");
@@ -472,34 +472,34 @@ void Test::testCellStringPool()
m_pDoc->SetString(ScAddress(0,3,0), "andy"); // A4
m_pDoc->SetString(ScAddress(0,4,0), "BRUCE"); // A5
sal_uIntPtr nId1 = m_pDoc->GetCellStringID(ScAddress(0,0,0));
sal_uIntPtr nId2 = m_pDoc->GetCellStringID(ScAddress(0,1,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId1);
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId2);
CPPUNIT_ASSERT_EQUAL(nId1, nId2);
{
// These two shared string objects must go out of scope before the purge test.
svl::SharedString aSS1 = m_pDoc->GetSharedString(ScAddress(0,0,0));
svl::SharedString aSS2 = m_pDoc->GetSharedString(ScAddress(0,1,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid shared string.", aSS1.isValid());
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid shared string.", aSS2.isValid());
CPPUNIT_ASSERT_EQUAL(aSS1.getData(), aSS2.getData());
nId2 = m_pDoc->GetCellStringID(ScAddress(0,2,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2);
aSS2 = m_pDoc->GetSharedString(ScAddress(0,2,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", aSS1.getData() != aSS2.getData());
nId2 = m_pDoc->GetCellStringID(ScAddress(0,3,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2);
aSS2 = m_pDoc->GetSharedString(ScAddress(0,3,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", aSS1.getData() != aSS2.getData());
nId2 = m_pDoc->GetCellStringID(ScAddress(0,4,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2);
aSS2 = m_pDoc->GetSharedString(ScAddress(0,4,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", aSS1.getData() != aSS2.getData());
// A3 and A5 should differ but should be equal case-insensitively.
nId1 = m_pDoc->GetCellStringID(ScAddress(0,2,0));
nId2 = m_pDoc->GetCellStringID(ScAddress(0,4,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2);
// A3 and A5 should differ but should be equal case-insensitively.
aSS1 = m_pDoc->GetSharedString(ScAddress(0,2,0));
aSS2 = m_pDoc->GetSharedString(ScAddress(0,4,0));
CPPUNIT_ASSERT_MESSAGE("They must differ", aSS1.getData() != aSS2.getData());
CPPUNIT_ASSERT_MESSAGE("They must be equal when cases are ignored.", aSS1.getDataIgnoreCase() == aSS2.getDataIgnoreCase());
nId1 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,2,0));
nId2 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,4,0));
CPPUNIT_ASSERT_MESSAGE("They must be equal when cases are ignored.", nId1 == nId2);
// A2 and A4 should be equal when ignoring cases.
nId1 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,1,0));
nId2 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,3,0));
CPPUNIT_ASSERT_MESSAGE("They must be equal when cases are ignored.", nId1 == nId2);
// A2 and A4 should be equal when ignoring cases.
aSS1 = m_pDoc->GetSharedString(ScAddress(0,1,0));
aSS2 = m_pDoc->GetSharedString(ScAddress(0,3,0));
CPPUNIT_ASSERT_MESSAGE("They must be equal when cases are ignored.", aSS1.getDataIgnoreCase() == aSS2.getDataIgnoreCase());
}
// Check the string counts after purging. Purging shouldn't remove any strings in this case.
svl::SharedStringPool& rPool = m_pDoc->GetSharedStringPool();
@@ -568,24 +568,24 @@ void Test::testCellStringPool()
m_pDoc->SetEditText(ScAddress(1,0,0), rEE.CreateTextObject()); // B1
// These two should be equal.
nId1 = m_pDoc->GetCellStringID(ScAddress(0,0,0));
nId2 = m_pDoc->GetCellStringID(ScAddress(1,0,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId1);
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId2);
CPPUNIT_ASSERT_EQUAL(nId1, nId2);
svl::SharedString aSS1 = m_pDoc->GetSharedString(ScAddress(0,0,0));
svl::SharedString aSS2 = m_pDoc->GetSharedString(ScAddress(1,0,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", aSS1.isValid());
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", aSS2.isValid());
CPPUNIT_ASSERT_EQUAL(aSS1.getData(), aSS2.getData());
rEE.SetText("ANDY and BRUCE");
m_pDoc->SetEditText(ScAddress(2,0,0), rEE.CreateTextObject()); // C1
nId2 = m_pDoc->GetCellStringID(ScAddress(2,0,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId2);
CPPUNIT_ASSERT_MESSAGE("These two should be different when cases are considered.", nId1 != nId2);
aSS2 = m_pDoc->GetSharedString(ScAddress(2,0,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", aSS2.isValid());
CPPUNIT_ASSERT_MESSAGE("These two should be different when cases are considered.", aSS1.getData() != aSS2.getData());
// But they should be considered equal when cases are ignored.
nId1 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,0,0));
nId2 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(2,0,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId1);
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId2);
CPPUNIT_ASSERT_EQUAL(nId1, nId2);
aSS1 = m_pDoc->GetSharedString(ScAddress(0,0,0));
aSS2 = m_pDoc->GetSharedString(ScAddress(2,0,0));
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", aSS1.isValid());
CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", aSS2.isValid());
CPPUNIT_ASSERT_EQUAL(aSS1.getDataIgnoreCase(), aSS2.getDataIgnoreCase());
m_pDoc->DeleteTab(0);
}
+2 -2
View File
@@ -80,7 +80,7 @@ public:
*/
void testPerf();
void testCollator();
void testCellStringPool();
void testSharedStringPool();
void testRangeList();
void testInput();
@@ -285,7 +285,7 @@ public:
CPPUNIT_TEST(testPerf);
#endif
CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testCellStringPool);
CPPUNIT_TEST(testSharedStringPool);
CPPUNIT_TEST(testRangeList);
CPPUNIT_TEST(testInput);
CPPUNIT_TEST(testFormulaHashAndTag);
+7 -41
View File
@@ -1736,62 +1736,28 @@ bool ScColumn::SetGroupFormulaCell( SCROW nRow, ScFormulaCell* pCell )
return true;
}
sal_uIntPtr ScColumn::GetCellStringID( SCROW nRow ) const
svl::SharedString ScColumn::GetSharedString( SCROW nRow ) const
{
sc::CellStoreType::const_position_type aPos = maCells.position(nRow);
switch (aPos.first->type)
{
case sc::element_type_string:
{
const svl::SharedString& rStr = sc::string_block::at(*aPos.first->data, aPos.second);
return reinterpret_cast<sal_uIntPtr>(rStr.getData());
}
break;
return sc::string_block::at(*aPos.first->data, aPos.second);
case sc::element_type_edittext:
{
std::vector<sal_uIntPtr> aIDs;
const EditTextObject* pObj = sc::edittext_block::at(*aPos.first->data, aPos.second);
pObj->GetStringIDs(pDocument->GetSharedStringPool(), aIDs);
if (aIDs.size() != 1)
std::vector<svl::SharedString> aSSs = pObj->GetSharedStrings();
if (aSSs.size() != 1)
// We don't handle multiline content for now.
return 0;
return svl::SharedString();
return aIDs[0];
return aSSs[0];
}
break;
default:
;
}
return 0;
}
sal_uIntPtr ScColumn::GetCellStringIDIgnoreCase( SCROW nRow ) const
{
sc::CellStoreType::const_position_type aPos = maCells.position(nRow);
switch (aPos.first->type)
{
case sc::element_type_string:
{
const svl::SharedString& rStr = sc::string_block::at(*aPos.first->data, aPos.second);
return reinterpret_cast<sal_uIntPtr>(rStr.getDataIgnoreCase());
}
break;
case sc::element_type_edittext:
{
std::vector<sal_uIntPtr> aIDs;
const EditTextObject* pObj = sc::edittext_block::at(*aPos.first->data, aPos.second);
pObj->GetStringIDsIgnoreCase(pDocument->GetSharedStringPool(), aIDs);
if (aIDs.size() != 1)
// We don't handle multiline content for now.
return 0;
return aIDs[0];
}
break;
default:
;
}
return 0;
return svl::SharedString();
}
namespace {
+3 -11
View File
@@ -3213,20 +3213,12 @@ double* ScDocument::GetValueCell( const ScAddress& rPos )
return maTabs[rPos.Tab()]->GetValueCell(rPos.Col(), rPos.Row());
}
sal_uIntPtr ScDocument::GetCellStringID( const ScAddress& rPos ) const
svl::SharedString ScDocument::GetSharedString( const ScAddress& rPos ) const
{
if (!TableExists(rPos.Tab()))
return 0;
return svl::SharedString();
return maTabs[rPos.Tab()]->GetCellStringID(rPos.Col(), rPos.Row());
}
sal_uIntPtr ScDocument::GetCellStringIDIgnoreCase( const ScAddress& rPos ) const
{
if (!TableExists(rPos.Tab()))
return 0;
return maTabs[rPos.Tab()]->GetCellStringIDIgnoreCase(rPos.Col(), rPos.Row());
return maTabs[rPos.Tab()]->GetSharedString(rPos.Col(), rPos.Row());
}
void ScDocument::GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rString )
+3 -11
View File
@@ -1505,20 +1505,12 @@ bool ScTable::SetGroupFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell
return aCol[nCol].SetGroupFormulaCell(nRow, pCell);
}
sal_uIntPtr ScTable::GetCellStringID( SCCOL nCol, SCROW nRow ) const
svl::SharedString ScTable::GetSharedString( SCCOL nCol, SCROW nRow ) const
{
if (!ValidColRow(nCol, nRow))
return 0;
return svl::SharedString();
return aCol[nCol].GetCellStringID(nRow);
}
sal_uIntPtr ScTable::GetCellStringIDIgnoreCase( SCCOL nCol, SCROW nRow ) const
{
if (!ValidColRow(nCol, nRow))
return 0;
return aCol[nCol].GetCellStringIDIgnoreCase(nRow);
return aCol[nCol].GetSharedString(nRow);
}
void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
+10
View File
@@ -78,6 +78,11 @@ bool SharedString::operator== ( const SharedString& r ) const
return !r.mpData;
}
bool SharedString::operator!= ( const SharedString& r ) const
{
return !operator== (r);
}
OUString SharedString::getString() const
{
return mpData ? OUString(mpData) : OUString();
@@ -103,6 +108,11 @@ const rtl_uString* SharedString::getDataIgnoreCase() const
return mpDataIgnoreCase;
}
bool SharedString::isValid() const
{
return mpData != NULL;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-22
View File
@@ -52,28 +52,6 @@ SharedString SharedStringPool::intern( const OUString& rStr )
return SharedString(pOrig, aRes.first->pData);
}
sal_uIntPtr SharedStringPool::getIdentifier( const OUString& rStr ) const
{
StrHashType::const_iterator it = maStrPool.find(rStr);
return (it == maStrPool.end()) ? 0 : reinterpret_cast<sal_uIntPtr>(it->pData);
}
sal_uIntPtr SharedStringPool::getIdentifierIgnoreCase( const OUString& rStr ) const
{
StrHashType::const_iterator itOrig = maStrPool.find(rStr);
if (itOrig == maStrPool.end())
// Not in the pool.
return 0;
StrStoreType::const_iterator itUpper = maStrStore.find(itOrig->pData);
if (itUpper == maStrStore.end())
// Passed string is not in the pool.
return 0;
const rtl_uString* pUpper = itUpper->second.pData;
return reinterpret_cast<sal_uIntPtr>(pUpper);
}
namespace {
inline sal_Int32 getRefCount( const rtl_uString* p )