editeng/source/misc/svxacorr.cxx | 75 +++++++++++++++++++++++++-------------- include/editeng/svxacorr.hxx | 15 +++---- 2 files changed, 55 insertions(+), 35 deletions(-)
New commits: commit 3980fc115d4c816c3dca449752a151f7b1effea4 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Nov 22 13:23:44 2014 -0500 Apply pimpl to SvxAutocorrWordList. And remove <set> and <boost/unordered_map.hpp> header includes from its public header. Change-Id: I7e748009f718f4195bec2348383df07dc67600cd diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 0f4d257..931c42a 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -2691,34 +2691,55 @@ bool CompareSvxAutocorrWordList::operator()( SvxAutocorrWord* const& lhs, SvxAut 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; + +} + +struct SvxAutocorrWordList::Impl +{ + + // 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; + maHash.clear(); + + for (AutocorrWordSetType::const_iterator it2 = maSet.begin(); it2 != maSet.end(); ++it2) + delete *it2; + maSet.clear(); + } +}; + +SvxAutocorrWordList::SvxAutocorrWordList() : mpImpl(new Impl) {} SvxAutocorrWordList::~SvxAutocorrWordList() { - DeleteAndDestroyAll(); + mpImpl->DeleteAndDestroyAll(); + delete mpImpl; } void SvxAutocorrWordList::DeleteAndDestroyAll() { - for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it ) - delete it->second; - maHash.clear(); - - for( SvxAutocorrWordList_Set::const_iterator it2 = maSet.begin(); it2 != maSet.end(); ++it2 ) - delete *it2; - maSet.clear(); + mpImpl->DeleteAndDestroyAll(); } // returns true if inserted bool SvxAutocorrWordList::Insert(SvxAutocorrWord *pWord) const { - if ( maSet.empty() ) // use the hash + if ( mpImpl->maSet.empty() ) // use the hash { 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 - return maSet.insert( pWord ).second; + return mpImpl->maSet.insert( pWord ).second; } void SvxAutocorrWordList::LoadEntry(const OUString& sWrong, const OUString& sRight, bool bOnlyTxt) @@ -2730,29 +2751,29 @@ void SvxAutocorrWordList::LoadEntry(const OUString& sWrong, const OUString& sRig bool SvxAutocorrWordList::empty() const { - return maHash.empty() && maSet.empty(); + return mpImpl->maHash.empty() && mpImpl->maSet.empty(); } SvxAutocorrWord *SvxAutocorrWordList::FindAndRemove(SvxAutocorrWord *pWord) { SvxAutocorrWord *pMatch = NULL; - if ( maSet.empty() ) // use the hash + if ( mpImpl->maSet.empty() ) // use the hash { - SvxAutocorrWordList_Hash::iterator it = maHash.find( pWord->GetShort() ); - if( it != maHash.end() ) + AutocorrWordHashType::iterator it = mpImpl->maHash.find( pWord->GetShort() ); + if( it != mpImpl->maHash.end() ) { pMatch = it->second; - maHash.erase (it); + mpImpl->maHash.erase (it); } } else { - SvxAutocorrWordList_Set::iterator it = maSet.find( pWord ); - if( it != maSet.end() ) + AutocorrWordSetType::iterator it = mpImpl->maSet.find( pWord ); + if( it != mpImpl->maSet.end() ) { pMatch = *it; - maSet.erase (it); + mpImpl->maSet.erase (it); } } return pMatch; @@ -2764,14 +2785,14 @@ SvxAutocorrWordList::Content SvxAutocorrWordList::getSortedContent() const Content aContent; // 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. - for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it ) - maSet.insert( it->second ); - maHash.clear(); + for (AutocorrWordHashType::const_iterator it = mpImpl->maHash.begin(); it != mpImpl->maHash.end(); ++it) + mpImpl->maSet.insert( it->second ); + 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 ); return aContent; @@ -2888,13 +2909,13 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const OUString& rTxt, sal_Int32& rStt, 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 ) ) 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 ) ) return aTmp; diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx index 7e7886c..9e5f5da 100644 --- a/include/editeng/svxacorr.hxx +++ b/include/editeng/svxacorr.hxx @@ -32,8 +32,6 @@ #include <editeng/editengdllapi.h> #include <map> -#include <set> -#include <boost/unordered_map.hpp> #include <boost/ptr_container/ptr_map.hpp> class CharClass; @@ -137,19 +135,14 @@ struct CompareSvxAutocorrWordList 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 { + struct Impl; + Impl* mpImpl; + SvxAutocorrWordList( 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 OUString &rTxt, sal_Int32 &rStt, commit 05e01bad5d5387ec551dd8ef50be7197df518504 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Nov 22 12:37:09 2014 -0500 Make SvxAutocorrWordList explicitly non-copyable. Change-Id: Idc056fd216bfe0b5e5c0285b1781b0658837f5a2 diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 6b235de..0f4d257 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -2691,6 +2691,8 @@ bool CompareSvxAutocorrWordList::operator()( SvxAutocorrWord* const& lhs, SvxAut return rCmp.compareString( lhs->GetShort(), rhs->GetShort() ) < 0; } +SvxAutocorrWordList::SvxAutocorrWordList() {} + SvxAutocorrWordList::~SvxAutocorrWordList() { DeleteAndDestroyAll(); diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx index a885dd7..7e7886c 100644 --- a/include/editeng/svxacorr.hxx +++ b/include/editeng/svxacorr.hxx @@ -143,6 +143,9 @@ typedef ::boost::unordered_map< OUString, SvxAutocorrWord *, class EDITENG_DLLPUBLIC SvxAutocorrWordList { + SvxAutocorrWordList( 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' @@ -152,6 +155,7 @@ class EDITENG_DLLPUBLIC SvxAutocorrWordList sal_Int32 &rStt, sal_Int32 nEndPos) const; public: + SvxAutocorrWordList(); // free any objects still in the set ~SvxAutocorrWordList(); void DeleteAndDestroyAll(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits