]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_search_arg_to_imap() - minor FLAGS writing optimization
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 18 Apr 2017 12:51:39 +0000 (15:51 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 27 Apr 2017 07:26:49 +0000 (10:26 +0300)
Avoid an extra str_delete() by immediately calculating whether the
parenthesis are needed.

src/lib-storage/mail-search-args-imap.c

index c0d6e412084914db71e4d8714f89396e8d1fdfa2..f3c82fc09a113bd7fc47509882ff78299ced787a 100644 (file)
@@ -57,22 +57,20 @@ mail_search_arg_to_imap_flags(string_t *dest, enum mail_flags flags)
        static const char *flag_names[] = {
                "ANSWERED", "FLAGGED", "DELETED", "SEEN", "DRAFT", "RECENT"
        };
-       unsigned int count = 0, start_pos = str_len(dest);
 
-       str_append_c(dest, '(');
+       i_assert(flags != 0);
+
+       if (!bits_is_power_of_two(flags))
+               str_append_c(dest, '(');
        for (unsigned int i = 0; i < N_ELEMENTS(flag_names); i++) {
                if ((flags & (1 << i)) != 0) {
                        str_append(dest, flag_names[i]);
                        str_append_c(dest, ' ');
-                       count++;
                }
        }
-       i_assert(count > 0);
 
        str_truncate(dest, str_len(dest)-1);
-       if (count == 1)
-               str_delete(dest, start_pos, 1);
-       else
+       if (!bits_is_power_of_two(flags))
                str_append_c(dest, ')');
 }