From a7c7cc655f94acc4476e681ac258ff6981702944 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 30 Jun 2011 04:58:55 +0300 Subject: Small speed improve in guichan code. --- src/guichan/include/guichan/widget.hpp | 3 +++ src/guichan/widget.cpp | 15 +++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/guichan') diff --git a/src/guichan/include/guichan/widget.hpp b/src/guichan/include/guichan/widget.hpp index 0f8c803ca..ccb56ea70 100644 --- a/src/guichan/include/guichan/widget.hpp +++ b/src/guichan/include/guichan/widget.hpp @@ -45,6 +45,7 @@ #define GCN_WIDGET_HPP #include +#include #include #include "guichan/color.hpp" @@ -1196,6 +1197,8 @@ namespace gcn * Holds a list of all instances of widgets. */ static std::list mWidgets; + + static std::set mWidgetsSet; }; } diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp index e143e4a97..8ec3a8178 100644 --- a/src/guichan/widget.cpp +++ b/src/guichan/widget.cpp @@ -69,6 +69,7 @@ namespace gcn Font* Widget::mGlobalFont = NULL; DefaultFont Widget::mDefaultFont; std::list Widget::mWidgets; + std::set Widget::mWidgetsSet; Widget::Widget() : mForegroundColor(0x000000), @@ -87,6 +88,7 @@ namespace gcn mCurrentFont(NULL) { mWidgets.push_back(this); + mWidgetsSet.insert(this); } Widget::~Widget() @@ -104,6 +106,7 @@ namespace gcn _setFocusHandler(NULL); mWidgets.remove(this); + mWidgetsSet.erase(this); } void Widget::drawFrame(Graphics* graphics) @@ -482,16 +485,8 @@ namespace gcn bool Widget::widgetExists(const Widget* widget) { - bool result = false; - - std::list::iterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - if (*iter == widget) - return true; - } - - return result; + return mWidgetsSet.find(const_cast(widget)) + != mWidgetsSet.end(); } bool Widget::isTabInEnabled() const -- cgit v1.2.3-70-g09d2