[mutter] meta_workspace_set_builtin_struts(): optimize out non-changes



commit 6ffe5f83434e605081eeb2d47dba64f2890ab29d
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Wed Feb 10 09:48:46 2010 -0500

    meta_workspace_set_builtin_struts(): optimize out non-changes
    
    meta_workspace_set_builtin_struts() is slightly expensive; it involves
    discarding all our cached computed information about the layout of the
    workspace. So catch calls to set_builtin_struts() that don't change
    anything.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=609546

 src/core/workspace.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/core/workspace.c b/src/core/workspace.c
index 36d620f..5b61af5 100644
--- a/src/core/workspace.c
+++ b/src/core/workspace.c
@@ -959,6 +959,23 @@ ensure_work_areas_validated (MetaWorkspace *workspace)
   }
 }
 
+static gboolean
+strut_lists_equal (GSList *l,
+                   GSList *m)
+{
+  for (; l && m; l = l->next, m = m->next)
+    {
+      MetaStrut *a = l->data;
+      MetaStrut *b = m->data;
+
+      if (a->side != b->side ||
+          !meta_rectangle_equal (&a->rect, &b->rect))
+        return FALSE;
+    }
+
+  return l == NULL && m == NULL;
+}
+
 /**
  * meta_workspace_set_builtin_struts:
  * @workspace: a #MetaWorkspace
@@ -972,6 +989,12 @@ void
 meta_workspace_set_builtin_struts (MetaWorkspace *workspace,
                                    GSList        *struts)
 {
+  /* Reordering doesn't actually matter, so we don't catch all
+   * no-impact changes, but this is just a (possibly unnecessary
+   * anyways) optimization */
+  if (strut_lists_equal (struts, workspace->builtin_struts))
+    return;
+
   workspace_free_builtin_struts (workspace);
   workspace->builtin_struts = copy_strut_list (struts);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]