diff options
author | Benjamin Otte <otte@redhat.com> | 2015-05-28 17:40:55 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-05-28 17:41:47 +0200 |
commit | 03312371daafe3a94d888474eb53d7361d5ed432 (patch) | |
tree | a968cfbed1fc102c9e1d7998201bca6297f729d5 /gtk/gtkcssmatcher.c | |
parent | 59a7739fce02627e5e24b03d9e0837c8ce01aa7b (diff) | |
download | gtk+-03312371daafe3a94d888474eb53d7361d5ed432.tar.gz |
cssmatcher: Speed up common matching
first-child and last-child are the most common usages of the nth-child
machinery, so special-casing them makes sense.
Diffstat (limited to 'gtk/gtkcssmatcher.c')
-rw-r--r-- | gtk/gtkcssmatcher.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c index 14597ccf1b..a15232764b 100644 --- a/gtk/gtkcssmatcher.c +++ b/gtk/gtkcssmatcher.c @@ -358,6 +358,18 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node, { int pos, x; + /* special-case the common "first-child" and "last-child" */ + if (a == 0) + { + while (b > 0 && node != NULL) + { + b--; + node = prev_node_func (node); + } + + return b == 0 && node == NULL; + } + /* count nodes */ for (pos = 0; node != NULL; pos++) node = prev_node_func (node); @@ -366,9 +378,6 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node, * and return TRUE if X is integer >= 0 */ x = pos - b; - if (a == 0) - return x == 0; - if (x % a) return FALSE; |