summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorErkin Bahceci <erkinbah@gmail.com>2008-09-07 08:18:55 -0500
committerErkin Bahceci <erkinbah@gmail.com>2008-09-07 08:18:55 -0500
commit8f0d337bb4bad91d5987d1d0df7474ea5d02033c (patch)
treeffd161b8154a90f5ef872814a55bcc37110ed698 /src
parentb31b675fbf3db99ca3d481259732645ce07944d7 (diff)
downloadcompiz-with-glib-mainloop-8f0d337bb4bad91d5987d1d0df7474ea5d02033c.tar.gz
compiz-with-glib-mainloop-8f0d337bb4bad91d5987d1d0df7474ea5d02033c.tar.bz2
Use plugin and window maps for more efficient search.
Diffstat (limited to 'src')
-rw-r--r--src/plugin.cpp22
-rw-r--r--src/privatescreen.h1
-rw-r--r--src/screen.cpp19
-rw-r--r--src/window.cpp2
4 files changed, 34 insertions, 10 deletions
diff --git a/src/plugin.cpp b/src/plugin.cpp
index d1e2e4a..287d5a9 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -36,6 +36,7 @@
#include <compiz-core.h>
#include <compobject.h>
+CompPlugin::Map pluginsMap;
std::list<CompPlugin *> plugins;
class CorePluginVTable : public CompPlugin::VTable
@@ -444,11 +445,10 @@ CompPlugin::objectFiniPlugins (CompObject *o)
CompPlugin *
CompPlugin::find (const char *name)
{
- foreach (CompPlugin *p, plugins)
- {
- if (strcmp (p->vTable->name (), name) == 0)
- return p;
- }
+ CompPlugin::Map::iterator it = pluginsMap.find (name);
+
+ if (it != pluginsMap.end ())
+ return it->second;
return NULL;
}
@@ -507,7 +507,12 @@ CompPlugin::load (const char *name)
bool
CompPlugin::push (CompPlugin *p)
{
- if (find (p->vTable->name ()))
+ const char *name = p->vTable->name ();
+
+ std::pair<CompPlugin::Map::iterator, bool> insertRet =
+ pluginsMap.insert (std::pair<const char *, CompPlugin *> (name, p));
+
+ if (!insertRet.second)
{
compLogMessage (NULL, "core", CompLogLevelWarn,
"Plugin '%s' already active",
@@ -521,8 +526,9 @@ CompPlugin::push (CompPlugin *p)
if (!initPlugin (p))
{
compLogMessage (NULL, "core", CompLogLevelError,
- "Couldn't activate plugin '%s'", p->vTable->name ());
+ "Couldn't activate plugin '%s'", name);
+ pluginsMap.erase (name);
plugins.pop_front ();
return false;
@@ -542,6 +548,8 @@ CompPlugin::pop (void)
if (!p)
return 0;
+ pluginsMap.erase (p->vTable->name ());
+
finiPlugin (p);
plugins.pop_front ();
diff --git a/src/privatescreen.h b/src/privatescreen.h
index 028af17..1932eec 100644
--- a/src/privatescreen.h
+++ b/src/privatescreen.h
@@ -150,6 +150,7 @@ class PrivateScreen {
CompScreen *screen;
CompDisplay *display;
CompWindowList windows;
+ CompWindow::Map windowsMap;
Colormap colormap;
int screenNum;
diff --git a/src/screen.cpp b/src/screen.cpp
index c855ef4..cc99d4f 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -1396,9 +1396,10 @@ CompScreen::findWindow (Window id)
}
else
{
- foreach (CompWindow *w, priv->windows)
- if (w->id () == id)
- return (lastFoundWindow = w);
+ CompWindow::Map::iterator it = priv->windowsMap.find (id);
+
+ if (it != priv->windowsMap.end ())
+ return (lastFoundWindow = it->second);
}
return 0;
@@ -1445,6 +1446,8 @@ CompScreen::insertWindow (CompWindow *w, Window aboveId)
w->next = priv->windows.front ();
}
priv->windows.push_front (w);
+ if (w->id () != 1)
+ priv->windowsMap[w->id ()] = w;
return;
}
@@ -1476,6 +1479,15 @@ CompScreen::insertWindow (CompWindow *w, Window aboveId)
}
priv->windows.insert (++it, w);
+ if (w->id () != 1)
+ priv->windowsMap[w->id ()] = w;
+}
+
+void
+CompScreen::eraseWindowFromMap (Window id)
+{
+ if (id != 1)
+ priv->windowsMap.erase (id);
}
void
@@ -1485,6 +1497,7 @@ CompScreen::unhookWindow (CompWindow *w)
std::find (priv->windows.begin (), priv->windows.end (), w);
priv->windows.erase (it);
+ eraseWindowFromMap (w->id ());
if (w->next)
w->next->prev = w->prev;
diff --git a/src/window.cpp b/src/window.cpp
index 5a442b7..d495087 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1056,6 +1056,8 @@ setDefaultWindowAttributes (XWindowAttributes *wa)
void
CompWindow::destroy ()
{
+ screen ()->eraseWindowFromMap (id ());
+
priv->id = 1;
priv->mapNum = 0;