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 itl = d->words_.begin();
Private::LangWordsMap::const_iterator ite = d->words_.end(); Private::LangWordsMap::const_iterator ite = d->words_.end();
for (; itl != ite; ++itl) { 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 it = (itl->second).begin();
Private::Words::const_iterator et = (itl->second).end(); Private::Words::const_iterator et = (itl->second).end();
for (; it != et; ++it) for (; it != et; ++it)
wl->remove(*it); wl.remove(*it);
} }
d->words_.clear(); d->words_.clear();
} }
@ -3785,11 +3785,11 @@ void Paragraph::registerWords()
Private::LangWordsMap::const_iterator itl = d->words_.begin(); Private::LangWordsMap::const_iterator itl = d->words_.begin();
Private::LangWordsMap::const_iterator ite = d->words_.end(); Private::LangWordsMap::const_iterator ite = d->words_.end();
for (; itl != ite; ++itl) { 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 it = (itl->second).begin();
Private::Words::const_iterator et = (itl->second).end(); Private::Words::const_iterator et = (itl->second).end();
for (; it != et; ++it) for (; it != et; ++it)
wl->insert(*it); wl.insert(*it);
} }
} }

View File

@ -586,7 +586,7 @@ class TextCompletionList : public CompletionList
{ {
public: public:
/// ///
TextCompletionList(Cursor const & cur, WordList const * list) TextCompletionList(Cursor const & cur, WordList const & list)
: buffer_(cur.buffer()), list_(list) : buffer_(cur.buffer()), list_(list)
{} {}
/// ///
@ -597,19 +597,19 @@ public:
/// ///
virtual size_t size() const virtual size_t size() const
{ {
return list_->size(); return list_.size();
} }
/// ///
virtual docstring const & data(size_t idx) const virtual docstring const & data(size_t idx) const
{ {
return list_->word(idx); return list_.word(idx);
} }
private: private:
/// ///
Buffer const * buffer_; 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 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); return new TextCompletionList(cur, list);
} }

View File

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

View File

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