Kaydet (Commit) 3980fc11 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Apply pimpl to SvxAutocorrWordList.

And remove <set> and <boost/unordered_map.hpp> header includes from its
public header.

Change-Id: I7e748009f718f4195bec2348383df07dc67600cd
üst 05e01bad
...@@ -2691,34 +2691,55 @@ bool CompareSvxAutocorrWordList::operator()( SvxAutocorrWord* const& lhs, SvxAut ...@@ -2691,34 +2691,55 @@ bool CompareSvxAutocorrWordList::operator()( SvxAutocorrWord* const& lhs, SvxAut
return rCmp.compareString( lhs->GetShort(), rhs->GetShort() ) < 0; return rCmp.compareString( lhs->GetShort(), rhs->GetShort() ) < 0;
} }
SvxAutocorrWordList::SvxAutocorrWordList() {} namespace {
typedef std::set<SvxAutocorrWord*, CompareSvxAutocorrWordList> AutocorrWordSetType;
typedef boost::unordered_map<OUString, SvxAutocorrWord*, OUStringHash> AutocorrWordHashType;
SvxAutocorrWordList::~SvxAutocorrWordList()
{
DeleteAndDestroyAll();
} }
void SvxAutocorrWordList::DeleteAndDestroyAll() struct SvxAutocorrWordList::Impl
{ {
for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it )
// only one of these contains the data
mutable AutocorrWordSetType maSet;
mutable AutocorrWordHashType maHash; // key is 'Short'
void DeleteAndDestroyAll()
{
for (AutocorrWordHashType::const_iterator it = maHash.begin(); it != maHash.end(); ++it)
delete it->second; delete it->second;
maHash.clear(); maHash.clear();
for( SvxAutocorrWordList_Set::const_iterator it2 = maSet.begin(); it2 != maSet.end(); ++it2 ) for (AutocorrWordSetType::const_iterator it2 = maSet.begin(); it2 != maSet.end(); ++it2)
delete *it2; delete *it2;
maSet.clear(); maSet.clear();
}
};
SvxAutocorrWordList::SvxAutocorrWordList() : mpImpl(new Impl) {}
SvxAutocorrWordList::~SvxAutocorrWordList()
{
mpImpl->DeleteAndDestroyAll();
delete mpImpl;
}
void SvxAutocorrWordList::DeleteAndDestroyAll()
{
mpImpl->DeleteAndDestroyAll();
} }
// returns true if inserted // returns true if inserted
bool SvxAutocorrWordList::Insert(SvxAutocorrWord *pWord) const bool SvxAutocorrWordList::Insert(SvxAutocorrWord *pWord) const
{ {
if ( maSet.empty() ) // use the hash if ( mpImpl->maSet.empty() ) // use the hash
{ {
OUString aShort( pWord->GetShort() ); OUString aShort( pWord->GetShort() );
return maHash.insert( std::pair<OUString, SvxAutocorrWord *>( aShort, pWord ) ).second; return mpImpl->maHash.insert( std::pair<OUString, SvxAutocorrWord *>( aShort, pWord ) ).second;
} }
else else
return maSet.insert( pWord ).second; return mpImpl->maSet.insert( pWord ).second;
} }
void SvxAutocorrWordList::LoadEntry(const OUString& sWrong, const OUString& sRight, bool bOnlyTxt) void SvxAutocorrWordList::LoadEntry(const OUString& sWrong, const OUString& sRight, bool bOnlyTxt)
...@@ -2730,29 +2751,29 @@ void SvxAutocorrWordList::LoadEntry(const OUString& sWrong, const OUString& sRig ...@@ -2730,29 +2751,29 @@ void SvxAutocorrWordList::LoadEntry(const OUString& sWrong, const OUString& sRig
bool SvxAutocorrWordList::empty() const bool SvxAutocorrWordList::empty() const
{ {
return maHash.empty() && maSet.empty(); return mpImpl->maHash.empty() && mpImpl->maSet.empty();
} }
SvxAutocorrWord *SvxAutocorrWordList::FindAndRemove(SvxAutocorrWord *pWord) SvxAutocorrWord *SvxAutocorrWordList::FindAndRemove(SvxAutocorrWord *pWord)
{ {
SvxAutocorrWord *pMatch = NULL; SvxAutocorrWord *pMatch = NULL;
if ( maSet.empty() ) // use the hash if ( mpImpl->maSet.empty() ) // use the hash
{ {
SvxAutocorrWordList_Hash::iterator it = maHash.find( pWord->GetShort() ); AutocorrWordHashType::iterator it = mpImpl->maHash.find( pWord->GetShort() );
if( it != maHash.end() ) if( it != mpImpl->maHash.end() )
{ {
pMatch = it->second; pMatch = it->second;
maHash.erase (it); mpImpl->maHash.erase (it);
} }
} }
else else
{ {
SvxAutocorrWordList_Set::iterator it = maSet.find( pWord ); AutocorrWordSetType::iterator it = mpImpl->maSet.find( pWord );
if( it != maSet.end() ) if( it != mpImpl->maSet.end() )
{ {
pMatch = *it; pMatch = *it;
maSet.erase (it); mpImpl->maSet.erase (it);
} }
} }
return pMatch; return pMatch;
...@@ -2764,14 +2785,14 @@ SvxAutocorrWordList::Content SvxAutocorrWordList::getSortedContent() const ...@@ -2764,14 +2785,14 @@ SvxAutocorrWordList::Content SvxAutocorrWordList::getSortedContent() const
Content aContent; Content aContent;
// convert from hash to set permanantly // convert from hash to set permanantly
if ( maSet.empty() ) if ( mpImpl->maSet.empty() )
{ {
// This beasty has some O(N log(N)) in a terribly slow ICU collate fn. // This beasty has some O(N log(N)) in a terribly slow ICU collate fn.
for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it ) for (AutocorrWordHashType::const_iterator it = mpImpl->maHash.begin(); it != mpImpl->maHash.end(); ++it)
maSet.insert( it->second ); mpImpl->maSet.insert( it->second );
maHash.clear(); mpImpl->maHash.clear();
} }
for( SvxAutocorrWordList_Set::const_iterator it = maSet.begin(); it != maSet.end(); ++it ) for (AutocorrWordSetType::const_iterator it = mpImpl->maSet.begin(); it != mpImpl->maSet.end(); ++it)
aContent.push_back( *it ); aContent.push_back( *it );
return aContent; return aContent;
...@@ -2888,13 +2909,13 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p ...@@ -2888,13 +2909,13 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const OUString& rTxt, sal_Int32& rStt, const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const OUString& rTxt, sal_Int32& rStt,
sal_Int32 nEndPos) const sal_Int32 nEndPos) const
{ {
for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it ) for (AutocorrWordHashType::const_iterator it = mpImpl->maHash.begin(); it != mpImpl->maHash.end(); ++it)
{ {
if( const SvxAutocorrWord *aTmp = WordMatches( it->second, rTxt, rStt, nEndPos ) ) if( const SvxAutocorrWord *aTmp = WordMatches( it->second, rTxt, rStt, nEndPos ) )
return aTmp; return aTmp;
} }
for( SvxAutocorrWordList_Set::const_iterator it2 = maSet.begin(); it2 != maSet.end(); ++it2 ) for (AutocorrWordSetType::const_iterator it2 = mpImpl->maSet.begin(); it2 != mpImpl->maSet.end(); ++it2)
{ {
if( const SvxAutocorrWord *aTmp = WordMatches( *it2, rTxt, rStt, nEndPos ) ) if( const SvxAutocorrWord *aTmp = WordMatches( *it2, rTxt, rStt, nEndPos ) )
return aTmp; return aTmp;
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#include <editeng/editengdllapi.h> #include <editeng/editengdllapi.h>
#include <map> #include <map>
#include <set>
#include <boost/unordered_map.hpp>
#include <boost/ptr_container/ptr_map.hpp> #include <boost/ptr_container/ptr_map.hpp>
class CharClass; class CharClass;
...@@ -137,19 +135,14 @@ struct CompareSvxAutocorrWordList ...@@ -137,19 +135,14 @@ struct CompareSvxAutocorrWordList
bool operator()( SvxAutocorrWord* const& lhs, SvxAutocorrWord* const& rhs ) const; bool operator()( SvxAutocorrWord* const& lhs, SvxAutocorrWord* const& rhs ) const;
}; };
typedef std::set<SvxAutocorrWord*, CompareSvxAutocorrWordList> SvxAutocorrWordList_Set;
typedef ::boost::unordered_map< OUString, SvxAutocorrWord *,
OUStringHash > SvxAutocorrWordList_Hash;
class EDITENG_DLLPUBLIC SvxAutocorrWordList class EDITENG_DLLPUBLIC SvxAutocorrWordList
{ {
struct Impl;
Impl* mpImpl;
SvxAutocorrWordList( const SvxAutocorrWordList& ); // disabled SvxAutocorrWordList( const SvxAutocorrWordList& ); // disabled
const SvxAutocorrWordList& operator= ( const SvxAutocorrWordList& ); // disabled const SvxAutocorrWordList& operator= ( const SvxAutocorrWordList& ); // disabled
// only one of these contains the data
mutable SvxAutocorrWordList_Set maSet;
mutable SvxAutocorrWordList_Hash maHash; // key is 'Short'
const SvxAutocorrWord* WordMatches(const SvxAutocorrWord *pFnd, const SvxAutocorrWord* WordMatches(const SvxAutocorrWord *pFnd,
const OUString &rTxt, const OUString &rTxt,
sal_Int32 &rStt, sal_Int32 &rStt,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment