[gtk+] cssmatcher: Simplify code
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssmatcher: Simplify code
- Date: Thu, 28 May 2015 15:42:26 +0000 (UTC)
commit 4847eff6c42a45c95d8115bf9c1dc294a9c108ba
Author: Benjamin Otte <otte redhat com>
Date: Thu May 28 17:06:53 2015 +0200
cssmatcher: Simplify code
Instead of copy/paste, pass the only difference as an argument
The code still doesn't work right, but at least it's easier to fix now.
gtk/gtkcssmatcher.c | 41 +++++++----------------------------------
1 files changed, 7 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index b2b5c75..c68f650 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -352,6 +352,7 @@ gtk_css_matcher_node_has_region (const GtkCssMatcher *matcher,
static gboolean
gtk_css_matcher_node_nth_child (GtkCssNode *node,
+ GtkCssNode *(* prev_node_func) (GtkCssNode *),
int a,
int b)
{
@@ -360,7 +361,7 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node,
if (node == NULL)
return FALSE;
- node = get_previous_visible_sibling (node);
+ node = prev_node_func (node);
}
if (a == 0)
@@ -372,35 +373,7 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node,
while (node)
{
b++;
- node = get_previous_visible_sibling (node);
- }
-
- return b % a == 0;
-}
-
-static gboolean
-gtk_css_matcher_node_nth_last_child (GtkCssNode *node,
- int a,
- int b)
-{
- while (b-- > 0)
- {
- if (node == NULL)
- return FALSE;
-
- node = get_next_visible_sibling (node);
- }
-
- if (a == 0)
- return node == NULL;
- else if (a == 1)
- return TRUE;
-
- b = 0;
- while (node)
- {
- b++;
- node = get_next_visible_sibling (node);
+ node = prev_node_func (node);
}
return b % a == 0;
@@ -412,10 +385,10 @@ gtk_css_matcher_node_has_position (const GtkCssMatcher *matcher,
int a,
int b)
{
- if (forward)
- return gtk_css_matcher_node_nth_child (matcher->node.node, a, b);
- else
- return gtk_css_matcher_node_nth_last_child (matcher->node.node, a, b);
+ return gtk_css_matcher_node_nth_child (matcher->node.node,
+ forward ? get_previous_visible_sibling
+ : get_next_visible_sibling,
+ a, b);
}
static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]