From: Stefan Schimanski Date: Thu, 21 Feb 2008 23:36:02 +0000 (+0000) Subject: * Reduce compilation time by removing the shared_ptr (which is not X-Git-Tag: 1.6.10~6180 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6eb72bd1f22879b7e991f46227cc6a86359f1ea3;p=features.git * Reduce compilation time by removing the shared_ptr (which is not really important because the ownership of the CompletionLists is easy enough) and by removing the deque for the half finished favorites implemention in InsetMathNest. I think this fits better into the GuiCompleter anyway. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23114 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiCompleter.cpp b/src/frontends/qt4/GuiCompleter.cpp index ff9b92d7f7..ed8813e131 100644 --- a/src/frontends/qt4/GuiCompleter.cpp +++ b/src/frontends/qt4/GuiCompleter.cpp @@ -72,8 +72,11 @@ protected: class GuiCompletionModel : public QAbstractListModel { public: /// - GuiCompletionModel(QObject * parent, Inset::CompletionListPtr l) - : QAbstractListModel(parent), list(l) {} + GuiCompletionModel(QObject * parent, Inset::CompletionList const * l) + : QAbstractListModel(parent), list_(l) {} + /// + ~GuiCompletionModel() + { delete list_; } /// int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const { @@ -82,16 +85,16 @@ public: /// int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const { - if (list.get() == 0) + if (list_ == 0) return 0; else - return list->size(); + return list_->size(); } /// QVariant data(const QModelIndex & index, int role) const { - if (list.get() == 0) + if (list_ == 0) return QVariant(); if (index.row() < 0 || index.row() >= rowCount()) @@ -101,11 +104,11 @@ public: return QVariant(); if (index.column() == 0) - return toqstr(list->data(index.row())); + return toqstr(list_->data(index.row())); else if (index.column() == 1) { // get icon from cache QPixmap scaled; - QString const name = ":" + toqstr(list->icon(index.row())); + QString const name = ":" + toqstr(list_->icon(index.row())); if (!QPixmapCache::find("completion" + name, scaled)) { // load icon from disk QPixmap p = QPixmap(name); @@ -125,7 +128,7 @@ public: private: /// - Inset::CompletionListPtr list; + Inset::CompletionList const * list_; }; @@ -133,7 +136,7 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent) : QCompleter(parent), gui_(gui), updateLock_(0) { // Setup the completion popup - setModel(new GuiCompletionModel(this, Inset::CompletionListPtr())); + setModel(new GuiCompletionModel(this, 0)); setCompletionMode(QCompleter::PopupCompletion); setWidget(gui_); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 4e7fc0d9a1..33a633f484 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -297,7 +297,6 @@ public: /// returns the resource string used to load an icon. virtual std::string icon(size_t /*idx*/) const { return std::string(); } }; - typedef boost::shared_ptr CompletionListPtr; /// Returns true if the inset supports completions. virtual bool completionSupported(Cursor const &) const { return false; } @@ -312,8 +311,9 @@ public: virtual bool automaticPopupCompletion() const { return true; } /// Returns completion suggestions at cursor position. Return an /// null pointer if no completion is a available or possible. - virtual CompletionListPtr completionList(Cursor const &) const - { return CompletionListPtr(); } + /// The caller is responsible to free the return object! + virtual CompletionList const * completionList(Cursor const &) const + { return 0; } /// Returns the completion prefix to filter the suggestions for completion. /// This is only called if completionList returned a non-null list. virtual docstring completionPrefix(Cursor const &) const diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 3b9060c7e0..9a36bc14b8 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -504,12 +504,12 @@ bool InsetText::automaticPopupCompletion() const } -Inset::CompletionListPtr InsetText::completionList(Cursor const & cur) const +Inset::CompletionList const * InsetText::completionList(Cursor const & cur) const { if (!completionSupported(cur)) - return CompletionListPtr(); + return 0; - return CompletionListPtr(new TextCompletionList(cur)); + return new TextCompletionList(cur); } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 94b3baebc2..ccb7301474 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -150,7 +150,7 @@ public: /// bool automaticPopupCompletion() const; /// - CompletionListPtr completionList(Cursor const & cur) const; + CompletionList const * completionList(Cursor const & cur) const; /// docstring completionPrefix(Cursor const & cur) const; /// diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 30e82c5b67..14ec77cfd0 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -58,7 +58,6 @@ #include "support/docstream.h" #include -#include #include using namespace std; @@ -1612,12 +1611,12 @@ bool InsetMathNest::automaticPopupCompletion() const } -Inset::CompletionListPtr InsetMathNest::completionList(Cursor const & cur) const +Inset::CompletionList const * InsetMathNest::completionList(Cursor const & cur) const { if (!cur.inMacroMode()) - return CompletionListPtr(); + return 0; - return CompletionListPtr(new MathCompletionList(cur)); + return new MathCompletionList(cur); } @@ -1805,20 +1804,17 @@ MathCompletionList::~MathCompletionList() size_type MathCompletionList::size() const { - return favorites.size() + locals.size() + globals.size(); + return locals.size() + globals.size(); } docstring MathCompletionList::data(size_t idx) const { - size_t fsize = favorites.size(); size_t lsize = locals.size(); - if (idx >= fsize + lsize) - return globals[idx - lsize - fsize]; - else if (idx >= fsize) - return locals[idx - fsize]; + if (idx >= lsize) + return globals[idx - lsize]; else - return favorites[idx]; + return locals[idx]; } @@ -1826,39 +1822,16 @@ std::string MathCompletionList::icon(size_t idx) const { // get the latex command docstring cmd; - size_t fsize = favorites.size(); size_t lsize = locals.size(); - if (idx >= fsize + lsize) - cmd = globals[idx - lsize - fsize]; - else if (idx >= fsize) - cmd = locals[idx - fsize]; + if (idx >= lsize) + cmd = globals[idx - lsize]; else - cmd = favorites[idx]; + cmd = locals[idx]; // get the icon resource name by stripping the backslash return "images/math/" + to_utf8(cmd.substr(1)) + ".png"; } - - -void MathCompletionList::addToFavorites(docstring const & completion) -{ - // remove old occurrence - std::deque::iterator it; - for (it = favorites.begin(); it != favorites.end(); ++it) { - if (*it == completion) { - favorites.erase(it); - break; - } - } - - // put it to the front - favorites.push_front(completion); - favorites.resize(min(int(favorites.size()), 10)); -} - - std::vector MathCompletionList::globals; -std::deque MathCompletionList::favorites; } // namespace lyx diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 3d990b2739..d164fe7525 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -14,8 +14,6 @@ #include "InsetMath.h" -#include - namespace lyx { class MathCompletionList : public Inset::CompletionList { @@ -40,8 +38,6 @@ private: static std::vector globals; /// std::vector locals; - /// - static std::deque favorites; }; /** Abstract base class for all math objects that contain nested items. @@ -146,7 +142,7 @@ public: /// bool automaticPopupCompletion() const; /// - CompletionListPtr completionList(Cursor const & cur) const; + CompletionList const * completionList(Cursor const & cur) const; /// docstring completionPrefix(Cursor const & cur) const; /// diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 3d84c65e9c..821ba2326d 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -763,12 +763,12 @@ bool MathMacro::automaticPopupCompletion() const } -Inset::CompletionListPtr MathMacro::completionList(Cursor const & cur) const +Inset::CompletionList const * MathMacro::completionList(Cursor const & cur) const { if (displayMode() != DISPLAY_UNFOLDED) return InsetMathNest::completionList(cur); - return CompletionListPtr(new MathCompletionList(cur.bv().cursor())); + return new MathCompletionList(cur.bv().cursor()); } diff --git a/src/mathed/MathMacro.h b/src/mathed/MathMacro.h index b74d383033..e0567a6468 100644 --- a/src/mathed/MathMacro.h +++ b/src/mathed/MathMacro.h @@ -186,7 +186,7 @@ public: /// bool automaticPopupCompletion() const; /// - CompletionListPtr completionList(Cursor const & cur) const; + CompletionList const * completionList(Cursor const & cur) const; /// docstring completionPrefix(Cursor const & cur) const; ///