[gtk/css-lookup-caching: 1/2] lookup: Don't store flat arrays
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/css-lookup-caching: 1/2] lookup: Don't store flat arrays
- Date: Sat, 8 Feb 2020 00:58:31 +0000 (UTC)
commit 37fa7b06ac1e00615d9d3f8cbe480f9cb2d9d474
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 26 17:16:19 2020 -0500
lookup: Don't store flat arrays
Most lookups have 0 or 1 value. We can drastically
reduce the amount of memory used for lookups, and
then we can afford to keep them around and avoid
some lookups in the future.
gtk/gtkcsslookup.c | 44 +++++++++++++++++++++++++++++++++++++++++---
gtk/gtkcsslookupprivate.h | 5 ++++-
gtk/gtkcssstaticstyle.c | 5 +++--
3 files changed, 48 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcsslookup.c b/gtk/gtkcsslookup.c
index 704de1560b..32cd64265f 100644
--- a/gtk/gtkcsslookup.c
+++ b/gtk/gtkcsslookup.c
@@ -24,18 +24,31 @@
#include "gtkprivatetypebuiltins.h"
#include "gtkprivate.h"
+static void
+free_value (gpointer data)
+{
+ GtkCssLookupValue *value = data;
+
+ gtk_css_value_unref (value->value);
+ if (value->section)
+ gtk_css_section_unref (value->section);
+}
+
void
_gtk_css_lookup_init (GtkCssLookup *lookup)
{
memset (lookup, 0, sizeof (*lookup));
lookup->set_values = _gtk_bitmask_new ();
+ lookup->values = g_array_new (FALSE, FALSE, sizeof (GtkCssLookupValue));
+ g_array_set_clear_func (lookup->values, free_value);
}
void
_gtk_css_lookup_destroy (GtkCssLookup *lookup)
{
_gtk_bitmask_free (lookup->set_values);
+ g_array_unref (lookup->values);
}
gboolean
@@ -66,11 +79,36 @@ _gtk_css_lookup_set (GtkCssLookup *lookup,
GtkCssSection *section,
GtkCssValue *value)
{
+ GtkCssLookupValue v;
+
gtk_internal_return_if_fail (lookup != NULL);
gtk_internal_return_if_fail (value != NULL);
- gtk_internal_return_if_fail (lookup->values[id].value == NULL);
+ gtk_internal_return_if_fail (_gtk_css_lookup_is_missing (lookup, id));
+
+ v.value = gtk_css_value_ref (value);
+ v.section = section ? gtk_css_section_ref (section) : NULL;
+ v.id = id;
- lookup->values[id].value = value;
- lookup->values[id].section = section;
+ g_array_append_val (lookup->values, v);
lookup->set_values = _gtk_bitmask_set (lookup->set_values, id, TRUE);
}
+
+GtkCssLookupValue *
+_gtk_css_lookup_get (GtkCssLookup *lookup,
+ guint id)
+{
+ gtk_internal_return_val_if_fail (lookup != NULL, NULL);
+
+ if (_gtk_bitmask_get (lookup->set_values, id))
+ {
+ int i;
+ for (i = 0; i < lookup->values->len; i++)
+ {
+ GtkCssLookupValue *value = &g_array_index (lookup->values, GtkCssLookupValue, i);
+ if (value->id == id)
+ return value;
+ }
+ }
+
+ return NULL;
+}
diff --git a/gtk/gtkcsslookupprivate.h b/gtk/gtkcsslookupprivate.h
index b433264c55..0dddbdad91 100644
--- a/gtk/gtkcsslookupprivate.h
+++ b/gtk/gtkcsslookupprivate.h
@@ -33,11 +33,12 @@ typedef struct _GtkCssLookup GtkCssLookup;
typedef struct {
GtkCssSection *section;
GtkCssValue *value;
+ guint id;
} GtkCssLookupValue;
struct _GtkCssLookup {
GtkBitmask *set_values;
- GtkCssLookupValue values[GTK_CSS_PROPERTY_N_PROPERTIES];
+ GArray *values;
};
void _gtk_css_lookup_init (GtkCssLookup *lookup);
@@ -48,6 +49,8 @@ void _gtk_css_lookup_set (GtkCssLookup
guint id,
GtkCssSection *section,
GtkCssValue *value);
+GtkCssLookupValue * _gtk_css_lookup_get (GtkCssLookup *lookup,
+ guint id);
static inline const GtkBitmask *
_gtk_css_lookup_get_set_values (const GtkCssLookup *lookup)
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 5a9336ce79..232c4edabb 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -211,12 +211,13 @@ gtk_css_ ## NAME ## _values_new_compute (GtkCssStaticStyle *sstyle, \
for (i = 0; i < G_N_ELEMENTS (NAME ## _props); i++) \
{ \
guint id = NAME ## _props[i]; \
+ GtkCssLookupValue *value = _gtk_css_lookup_get (lookup, id); \
gtk_css_static_style_compute_value (sstyle, \
provider, \
parent_style, \
id, \
- lookup->values[id].value, \
- lookup->values[id].section); \
+ value ? value->value : NULL, \
+ value ? value->section : NULL); \
} \
} \
static GtkBitmask * gtk_css_ ## NAME ## _values_mask; \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]