Convert a pointer to a reference

The validity of the reference is guaranteed by QThreadLocalStorage
This commit is contained in:
Guillaume Munch 2016-12-31 15:22:07 +01:00
parent 832b99a394
commit 0eb0b8531a
4 changed files with 13 additions and 13 deletions

View File

@ -3705,11 +3705,11 @@ void Paragraph::deregisterWords()
Private::LangWordsMap::const_iterator itl = d->words_.begin();
Private::LangWordsMap::const_iterator ite = d->words_.end();
for (; itl != ite; ++itl) {
WordList * wl = theWordList(itl->first);
WordList & wl = theWordList(itl->first);
Private::Words::const_iterator it = (itl->second).begin();
Private::Words::const_iterator et = (itl->second).end();
for (; it != et; ++it)
wl->remove(*it);
wl.remove(*it);
}
d->words_.clear();
}
@ -3785,11 +3785,11 @@ void Paragraph::registerWords()
Private::LangWordsMap::const_iterator itl = d->words_.begin();
Private::LangWordsMap::const_iterator ite = d->words_.end();
for (; itl != ite; ++itl) {
WordList * wl = theWordList(itl->first);
WordList & wl = theWordList(itl->first);
Private::Words::const_iterator it = (itl->second).begin();
Private::Words::const_iterator et = (itl->second).end();
for (; it != et; ++it)
wl->insert(*it);
wl.insert(*it);
}
}

View File

@ -586,7 +586,7 @@ class TextCompletionList : public CompletionList
{
public:
///
TextCompletionList(Cursor const & cur, WordList const * list)
TextCompletionList(Cursor const & cur, WordList const & list)
: buffer_(cur.buffer()), list_(list)
{}
///
@ -597,19 +597,19 @@ public:
///
virtual size_t size() const
{
return list_->size();
return list_.size();
}
///
virtual docstring const & data(size_t idx) const
{
return list_->word(idx);
return list_.word(idx);
}
private:
///
Buffer const * buffer_;
///
WordList const * list_;
WordList const & list_;
};
@ -2156,7 +2156,7 @@ bool Text::completionSupported(Cursor const & cur) const
CompletionList const * Text::createCompletionList(Cursor const & cur) const
{
WordList const * list = theWordList(cur.getFont().language()->lang());
WordList const & list = theWordList(cur.getFont().language()->lang());
return new TextCompletionList(cur, list);
}

View File

@ -34,18 +34,18 @@ typedef map<string, WordList *> GlobalWordList;
QThreadStorage<GlobalWordList *> theGlobalWordList;
WordList * theWordList(string const & lang)
WordList & theWordList(string const & lang)
{
if (!theGlobalWordList.hasLocalData())
theGlobalWordList.setLocalData(new GlobalWordList);
GlobalWordList * globalWordList = theGlobalWordList.localData();
GlobalWordList::iterator it = globalWordList->find(lang);
if (it != globalWordList->end())
return it->second;
return *it->second;
else {
WordList * wl = new WordList;
(*globalWordList)[lang] = wl;
return wl;
return *wl;
}
}

View File

@ -38,7 +38,7 @@ private:
std::unique_ptr<Impl> d;
};
WordList * theWordList(std::string const & lang);
WordList & theWordList(std::string const & lang);
} // namespace lyx