[devhelp/wip/swilmet/misc-improvements] Use bitfields for booleans in structs
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/swilmet/misc-improvements] Use bitfields for booleans in structs
- Date: Sun, 31 May 2015 07:23:56 +0000 (UTC)
commit b65a383b5f46908ac16ae4f55c7dcce26c891713
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun May 31 09:19:37 2015 +0200
Use bitfields for booleans in structs
It saves a little bit of memory. It's better to do it each time, so when
another boolean is added it's directly beneficial (and we don't need to
think all the time: should I write a bitfield of "gboolean"? Is the
struct heavily used or not? etc. It's simpler to always apply the same
convention).
src/dh-assistant-view.c | 2 +-
src/dh-book-manager.c | 6 +++---
src/dh-book-tree.c | 2 +-
src/dh-book.c | 3 ++-
src/dh-keyword-model.c | 2 +-
src/dh-parser.c | 8 ++++----
6 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/src/dh-assistant-view.c b/src/dh-assistant-view.c
index f4d911f..0f859a2 100644
--- a/src/dh-assistant-view.c
+++ b/src/dh-assistant-view.c
@@ -30,7 +30,7 @@ typedef struct {
DhBookManager *book_manager;
DhLink *link;
gchar *current_search;
- gboolean snippet_loaded;
+ guint snippet_loaded : 1;
} DhAssistantViewPriv;
enum {
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index 1b19c00..13c5fa2 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -44,13 +44,13 @@ typedef struct {
/* List of book names (gchar*) currently disabled */
GSList *books_disabled;
- /* Whether books should be grouped by language */
- gboolean group_by_language;
-
/* List of DhLanguage* with at least one book enabled */
GList *languages;
DhSettings *settings;
+
+ /* Whether books should be grouped by language */
+ guint group_by_language : 1;
} DhBookManagerPrivate;
enum {
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
index 3af7306..86da962 100644
--- a/src/dh-book-tree.c
+++ b/src/dh-book-tree.c
@@ -25,9 +25,9 @@
typedef struct {
const gchar *uri;
- gboolean found;
GtkTreeIter iter;
GtkTreePath *path;
+ guint found : 1;
} FindURIData;
typedef struct {
diff --git a/src/dh-book.c b/src/dh-book.c
index 987dd03..b0dc663 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -50,7 +50,6 @@ typedef enum {
/* Structure defining basic contents to store about every book */
typedef struct {
gchar *path;
- gboolean enabled;
gchar *name;
gchar *title;
gchar *language;
@@ -72,6 +71,8 @@ typedef struct {
/* ID of the event source */
guint monitor_event_timeout_id;
+
+ guint enabled : 1;
} DhBookPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (DhBook, dh_book, G_TYPE_OBJECT);
diff --git a/src/dh-keyword-model.c b/src/dh-keyword-model.c
index 7f04ff3..07f192c 100644
--- a/src/dh-keyword-model.c
+++ b/src/dh-keyword-model.c
@@ -45,9 +45,9 @@ typedef struct {
* word */
typedef struct {
gchar *keyword;
- gboolean has_glob;
GPatternSpec *glob_pattern_start;
GPatternSpec *glob_pattern_any;
+ guint has_glob : 1;
} DhKeywordGlobPattern;
#define MAX_HITS 100
diff --git a/src/dh-parser.c b/src/dh-parser.c
index 0b7018c..5d2e6b4 100644
--- a/src/dh-parser.c
+++ b/src/dh-parser.c
@@ -49,14 +49,14 @@ typedef struct {
/* Current sub section node */
GNode *parent;
- gboolean parsing_chapters;
- gboolean parsing_keywords;
-
- GNode **book_tree;
+ GNode **book_tree;
GList **keywords;
/* Version 2 uses <keyword> instead of <function>. */
gint version;
+
+ guint parsing_chapters : 1;
+ guint parsing_keywords : 1;
} DhParser;
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]