* mu-msg-fields: rewrite the loops a bit

This commit is contained in:
Dirk-Jan C. Binnema 2009-12-09 00:03:14 +02:00
parent 630a800ab2
commit e14703b58e
1 changed files with 10 additions and 15 deletions

View File

@ -115,19 +115,15 @@ static const MuMsgField FIELD_DATA[] = {
MU_MSG_FIELD_ID_TIMESTAMP, MU_MSG_FIELD_ID_TIMESTAMP,
MU_MSG_FIELD_TYPE_TIME_T, MU_MSG_FIELD_TYPE_TIME_T,
FLAG_GMIME FLAG_GMIME
}, }
{ NULL, NULL, NULL, 0, 0, 0 }
}; };
void void
mu_msg_field_foreach (MuMsgFieldForEachFunc func, gconstpointer data) mu_msg_field_foreach (MuMsgFieldForEachFunc func, gconstpointer data)
{ {
const MuMsgField* cursor = &FIELD_DATA[0]; int i;
while (cursor->_name) { for (i = 0; i != sizeof(FIELD_DATA)/sizeof(FIELD_DATA[0]); ++i)
func (cursor, data); func (&FIELD_DATA[i], data);
++cursor;
}
} }
typedef gboolean (*FieldMatchFunc) (const MuMsgField *field, typedef gboolean (*FieldMatchFunc) (const MuMsgField *field,
@ -136,12 +132,11 @@ typedef gboolean (*FieldMatchFunc) (const MuMsgField *field,
static const MuMsgField* static const MuMsgField*
find_field (FieldMatchFunc matcher, gconstpointer data) find_field (FieldMatchFunc matcher, gconstpointer data)
{ {
const MuMsgField* cursor = &FIELD_DATA[0]; int i;
while (cursor->_name) { for (i = 0; i != sizeof(FIELD_DATA)/sizeof(FIELD_DATA[0]); ++i)
if (matcher (cursor, data)) if (matcher(&FIELD_DATA[i], data))
return cursor; return &FIELD_DATA[i];
++cursor;
}
return NULL; return NULL;
} }
@ -186,7 +181,7 @@ mu_msg_field_from_id (MuMsgFieldId id)
gboolean 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); g_return_val_if_fail (field, FALSE);
return field->_flags & FLAG_XAPIAN; return field->_flags & FLAG_XAPIAN;