[devhelp] DhLink: factor out dh_link_type_compare() internal function



commit b7af8710af7dc0a6bf0386bedff318ecba647820
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 7 16:52:16 2017 +0100

    DhLink: factor out dh_link_type_compare() internal function

 src/dh-link.c |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/dh-link.c b/src/dh-link.c
index 3149392..f1dadb3 100644
--- a/src/dh-link.c
+++ b/src/dh-link.c
@@ -432,6 +432,25 @@ dh_link_get_book_id (DhLink *link)
         return "";
 }
 
+static gint
+dh_link_type_compare (DhLinkType a,
+                      DhLinkType b)
+{
+        if (a == b)
+                return 0;
+
+        /* Sort page links before other links. The page is more important than a
+         * symbol (typically contained in that page).
+         */
+        if (a == DH_LINK_TYPE_PAGE)
+                return -1;
+
+        if (b == DH_LINK_TYPE_PAGE)
+                return 1;
+
+        return 0;
+}
+
 /**
  * dh_link_compare:
  * @a: (type DhLink): a #DhLink.
@@ -471,23 +490,10 @@ dh_link_compare (gconstpointer a,
         diff = strcmp (la->name_collation_key,
                        lb->name_collation_key);
 
-        /* For the same names, sort page links before other links. The page is
-         * more important than a symbol (typically contained in that page).
-         */
-        if (diff == 0) {
-                if (la->type == lb->type)
-                        return 0;
-
-                if (la->type == DH_LINK_TYPE_PAGE)
-                        return -1;
-
-                if (lb->type == DH_LINK_TYPE_PAGE)
-                        return 1;
-
-                return 0;
-        }
+        if (diff != 0)
+                return diff;
 
-        return diff;
+        return dh_link_type_compare (la->type, lb->type);
 }
 
 /**


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