commit 4a5c79993cee3296da9a9e9311264b8c14dc928e
parent 6b9d4311d284debb0dba1d32757c965150d0d1d1
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date: Fri, 26 Nov 2021 12:24:47 +0100
optimize IMAP flag parsing
uppercase the reference strings and utilize already known string
lengths.
Diffstat:
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/drv_imap.c b/src/drv_imap.c
@@ -269,13 +269,17 @@ static int imap_deref( imap_store_t *ctx );
static void imap_invoke_bad_callback( imap_store_t *ctx );
// Keep the MESSAGE_FLAGS in sync (grep that)!
-static const char *Flags[] = {
- "\\Draft", /* 'D' */
- "\\Flagged", /* 'F' */
- "$Forwarded", /* 'P' */
- "\\Answered", /* 'R' */
- "\\Seen", /* 'S' */
- "\\Deleted", /* 'T' */
+static const struct {
+ const char *str;
+ const char *ustr;
+ uint len;
+} Flags[] = {
+ { "\\Draft", "\\DRAFT", 6 }, // 'D'
+ { "\\Flagged", "\\FLAGGED", 8 }, // 'F'
+ { "$Forwarded", "$FORWARDED", 10 }, // 'P'
+ { "\\Answered", "\\ANSWERED", 9 }, // 'R'
+ { "\\Seen", "\\SEEN", 5 }, // 'S'
+ { "\\Deleted", "\\DELETED", 8 }, // 'T'
};
static imap_cmd_t *
@@ -1092,7 +1096,7 @@ parse_fetched_flags( list_t *list, uchar *flags, uchar *status )
goto flagok;
}
for (uint i = 0; i < as(Flags); i++) {
- if (!strcasecmp( Flags[i], list->val )) {
+ if (equals( list->val, list->len, Flags[i].ustr, Flags[i].len )) {
*flags |= 1 << i;
goto flagok;
}
@@ -3060,7 +3064,7 @@ imap_make_flags( int flags, char *buf )
for (i = d = 0; i < as(Flags); i++) {
if (flags & (1 << i)) {
buf[d++] = ' ';
- for (s = Flags[i]; *s; s++)
+ for (s = Flags[i].str; *s; s++)
buf[d++] = *s;
}
}