From e14703b58ecd056f36f05f6878a43af8937ab006 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 9 Dec 2009 00:03:14 +0200 Subject: [PATCH] * mu-msg-fields: rewrite the loops a bit --- src/mu-msg-fields.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/mu-msg-fields.c b/src/mu-msg-fields.c index 7df38852..4616eddb 100644 --- a/src/mu-msg-fields.c +++ b/src/mu-msg-fields.c @@ -115,19 +115,15 @@ static const MuMsgField FIELD_DATA[] = { MU_MSG_FIELD_ID_TIMESTAMP, MU_MSG_FIELD_TYPE_TIME_T, FLAG_GMIME - }, - - { NULL, NULL, NULL, 0, 0, 0 } + } }; void mu_msg_field_foreach (MuMsgFieldForEachFunc func, gconstpointer data) { - const MuMsgField* cursor = &FIELD_DATA[0]; - while (cursor->_name) { - func (cursor, data); - ++cursor; - } + int i; + for (i = 0; i != sizeof(FIELD_DATA)/sizeof(FIELD_DATA[0]); ++i) + func (&FIELD_DATA[i], data); } typedef gboolean (*FieldMatchFunc) (const MuMsgField *field, @@ -136,12 +132,11 @@ typedef gboolean (*FieldMatchFunc) (const MuMsgField *field, static const MuMsgField* find_field (FieldMatchFunc matcher, gconstpointer data) { - const MuMsgField* cursor = &FIELD_DATA[0]; - while (cursor->_name) { - if (matcher (cursor, data)) - return cursor; - ++cursor; - } + int i; + for (i = 0; i != sizeof(FIELD_DATA)/sizeof(FIELD_DATA[0]); ++i) + if (matcher(&FIELD_DATA[i], data)) + return &FIELD_DATA[i]; + return NULL; } @@ -186,7 +181,7 @@ mu_msg_field_from_id (MuMsgFieldId id) gboolean -mu_msg_field_is_xapian_enabled (const MuMsgField *field) +mu_msg_field_is_xapian_enabled (const MuMsgField *field) { g_return_val_if_fail (field, FALSE); return field->_flags & FLAG_XAPIAN;