summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-10-18 11:29:15 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-10-19 09:05:05 +0200
commit856df6d40690500453092419b2c71e91e2c5de25 (patch)
tree191cde5bcb04fbfeccf5333243cab523f65c40fd /editeng
parent8c9cfba67711d0c3902f9bba444b68c7415d4f98 (diff)
use std::unique_ptr in TrieNode
Change-Id: I1482f846370e0b8e6f76d46fc5020e2dcb152223 Reviewed-on: https://gerrit.libreoffice.org/43495 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/lookuptree/Trie.cxx45
1 files changed, 12 insertions, 33 deletions
diff --git a/editeng/source/lookuptree/Trie.cxx b/editeng/source/lookuptree/Trie.cxx
index b661d6d81010..0badcd99703c 100644
--- a/editeng/source/lookuptree/Trie.cxx
+++ b/editeng/source/lookuptree/Trie.cxx
@@ -22,12 +22,10 @@ struct TrieNode final
sal_Unicode mCharacter;
bool mMarker;
- std::vector<TrieNode*> mChildren;
- TrieNode* mLatinArray[LATIN_ARRAY_SIZE];
-
+ std::vector<std::unique_ptr<TrieNode>> mChildren;
+ std::unique_ptr<TrieNode> mLatinArray[LATIN_ARRAY_SIZE];
explicit TrieNode(sal_Unicode aCharacter = '\0');
- ~TrieNode();
void markWord();
TrieNode* findChild(sal_Unicode aCharacter);
@@ -41,26 +39,12 @@ TrieNode::TrieNode(sal_Unicode aCharacter) :
mCharacter(aCharacter),
mMarker(false)
{
- for (TrieNode* & i : mLatinArray)
+ for (auto & i : mLatinArray)
{
i = nullptr;
}
}
-TrieNode::~TrieNode()
-{
- vector<TrieNode*>::iterator iNode;
- for(iNode = mChildren.begin(); iNode != mChildren.end(); ++iNode)
- {
- delete *iNode;
- }
-
- for (TrieNode* i : mLatinArray)
- {
- delete i;
- }
-}
-
void TrieNode::markWord()
{
mMarker = true;
@@ -71,11 +55,11 @@ void TrieNode::addNewChild(TrieNode* pChild)
if (pChild->mCharacter >= 'a' &&
pChild->mCharacter <= 'z')
{
- mLatinArray[pChild->mCharacter - u'a'] = pChild;
+ mLatinArray[pChild->mCharacter - u'a'].reset(pChild);
}
else
{
- mChildren.push_back(pChild);
+ mChildren.push_back(std::unique_ptr<TrieNode>(pChild));
}
}
@@ -84,16 +68,13 @@ TrieNode* TrieNode::findChild(sal_Unicode aInputCharacter)
if (aInputCharacter >= 'a' &&
aInputCharacter <= 'z')
{
- return mLatinArray[aInputCharacter - u'a'];
+ return mLatinArray[aInputCharacter - u'a'].get();
}
- vector<TrieNode*>::iterator iNode;
-
- for(iNode = mChildren.begin(); iNode != mChildren.end(); ++iNode)
+ for(auto const & pCurrent : mChildren)
{
- TrieNode* pCurrent = *iNode;
if ( pCurrent->mCharacter == aInputCharacter )
- return pCurrent;
+ return pCurrent.get();
}
return nullptr;
@@ -102,19 +83,17 @@ TrieNode* TrieNode::findChild(sal_Unicode aInputCharacter)
void TrieNode::collectSuggestions(const OUString& sPath, vector<OUString>& rSuggestionList)
{
// first traverse nodes for alphabet characters
- for (TrieNode* pCurrent : mLatinArray)
+ for (auto const & pCurrent : mLatinArray)
{
if (pCurrent != nullptr)
- collectSuggestionsForCurrentNode(pCurrent, sPath, rSuggestionList);
+ collectSuggestionsForCurrentNode(pCurrent.get(), sPath, rSuggestionList);
}
// traverse nodes for other characters
- vector<TrieNode*>::iterator iNode;
- for(iNode = mChildren.begin(); iNode != mChildren.end(); ++iNode)
+ for(auto const & pCurrent : mChildren)
{
- TrieNode* pCurrent = *iNode;
if (pCurrent != nullptr)
- collectSuggestionsForCurrentNode(pCurrent, sPath, rSuggestionList);
+ collectSuggestionsForCurrentNode(pCurrent.get(), sPath, rSuggestionList);
}
}