summaryrefslogtreecommitdiff
path: root/gtk/gtkcssmatcher.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-05-28 17:12:57 +0200
committerBenjamin Otte <otte@redhat.com>2015-05-28 17:12:57 +0200
commit59a7739fce02627e5e24b03d9e0837c8ce01aa7b (patch)
treee7f9e60efe924e0d01dd605526455ed7d56b80a4 /gtk/gtkcssmatcher.c
parent4847eff6c42a45c95d8115bf9c1dc294a9c108ba (diff)
downloadgtk+-59a7739fce02627e5e24b03d9e0837c8ce01aa7b.tar.gz
cssmatcher: Rewrite nth-child matcher
Instead of trying to be smart, be stupid but correct. Fixes nth-child reftest.
Diffstat (limited to 'gtk/gtkcssmatcher.c')
-rw-r--r--gtk/gtkcssmatcher.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index c68f650915..14597ccf1b 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -356,27 +356,23 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node,
int a,
int b)
{
- while (b-- > 0)
- {
- if (node == NULL)
- return FALSE;
+ int pos, x;
- node = prev_node_func (node);
- }
+ /* count nodes */
+ for (pos = 0; node != NULL; pos++)
+ node = prev_node_func (node);
+
+ /* solve pos = a * X + b
+ * and return TRUE if X is integer >= 0 */
+ x = pos - b;
if (a == 0)
- return node == NULL;
- else if (a == 1)
- return TRUE;
+ return x == 0;
- b = 0;
- while (node)
- {
- b++;
- node = prev_node_func (node);
- }
+ if (x % a)
+ return FALSE;
- return b % a == 0;
+ return x / a > 0;
}
static gboolean