[devhelp] Preferences: improve code of bookshelf_find_book()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Preferences: improve code of bookshelf_find_book()
- Date: Thu, 5 Apr 2018 19:18:39 +0000 (UTC)
commit 2f1cb1cef43fb95181fc2f8cddd65a937cea4d66
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Apr 5 21:13:35 2018 +0200
Preferences: improve code of bookshelf_find_book()
Compare pointers to NULL to make the code clearer (so that we know that
it's a pointer and not a boolean variable when reading the condition).
src/dh-preferences.c | 40 +++++++++++++++++++++++-----------------
1 files changed, 23 insertions(+), 17 deletions(-)
---
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index 017089c..60ea790 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -99,19 +99,21 @@ bookshelf_find_book (DhPreferences *prefs,
DhPreferencesPrivate *priv = dh_preferences_get_instance_private (prefs);
GtkTreeIter loop_iter;
- g_assert ((exact_iter && exact_found) || (next_iter && next_found));
+ g_assert ((exact_iter != NULL && exact_found != NULL) ||
+ (next_iter != NULL && next_found != NULL));
- /* Reset all flags to not found */
- if (exact_found)
+ if (exact_found != NULL)
*exact_found = FALSE;
- if (next_found)
+ if (next_found != NULL)
*next_found = FALSE;
/* Setup iteration start */
- if (!first) {
- /* If no first given, start iterating from the start of the model */
+ if (first == NULL) {
+ /* If no first given, start iterating from the start of the
+ * model.
+ */
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->bookshelf_store), &loop_iter)) {
- /* Store is empty, not found */
+ /* Store is empty, not found. */
return;
}
} else {
@@ -126,25 +128,30 @@ bookshelf_find_book (DhPreferences *prefs,
COLUMN_BOOK, &in_list_book,
-1);
- /* We may have reached the start of the next language group here */
- if (first && !in_list_book) {
+ /* We may have reached the start of the next language group
+ * here.
+ */
+ if (first != NULL && in_list_book == NULL) {
*next_iter = loop_iter;
*next_found = TRUE;
return;
}
- /* We can compare pointers directly as we're playing with references
- * of the same object */
- if (exact_iter &&
+ /* We can compare pointers directly as we're playing with
+ * references of the same object.
+ */
+ if (exact_iter != NULL &&
in_list_book == book) {
*exact_iter = loop_iter;
*exact_found = TRUE;
- if (!next_iter) {
- /* If we were not requested to look for the next one, end here */
+ if (next_iter == NULL) {
+ /* If we were not requested to look for the next
+ * one, end here.
+ */
g_object_unref (in_list_book);
return;
}
- } else if (next_iter &&
+ } else if (next_iter != NULL &&
dh_book_cmp_by_title (in_list_book, book) > 0) {
*next_iter = loop_iter;
*next_found = TRUE;
@@ -152,8 +159,7 @@ bookshelf_find_book (DhPreferences *prefs,
return;
}
- if (in_list_book)
- g_object_unref (in_list_book);
+ g_clear_object (&in_list_book);
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->bookshelf_store),
&loop_iter));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]