]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
director: Avoid str_printfa() in director_connection_send_users()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 4 Nov 2017 13:29:29 +0000 (15:29 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 6 Nov 2017 07:34:32 +0000 (09:34 +0200)
Optimizes the CPU usage.

src/director/director-connection.c

index e8726abbcce4bc9af0666e31c30f33353bb55e51..812b308e584c27f58c610f7ad7d2b750a2c5f7b8 100644 (file)
@@ -1980,23 +1980,24 @@ static int director_connection_send_done(struct director_connection *conn)
 static int director_connection_send_users(struct director_connection *conn)
 {
        struct user *user;
+       string_t *str = t_str_new(128);
+       char dec_buf[MAX_INT_STRLEN];
        int ret;
 
        i_assert(conn->version_received);
 
        while ((user = director_iterate_users_next(conn->user_iter)) != NULL) {
-               T_BEGIN {
-                       string_t *str = t_str_new(128);
-
-                       str_printfa(str, "USER\t%u\t%s\t%u",
-                                   user->username_hash,
-                                   user->host->ip_str,
-                                   user->timestamp);
-                       if (user->weak)
-                               str_append(str, "\tw");
-                       str_append_c(str, '\n');
-                       director_connection_send(conn, str_c(str));
-               } T_END;
+               str_truncate(str, 0);
+               str_append(str, "USER\t");
+               str_append(str, dec2str_buf(dec_buf, user->username_hash));
+               str_append_c(str, '\t');
+               str_append(str, user->host->ip_str);
+               str_append_c(str, '\t');
+               str_append(str, dec2str_buf(dec_buf, user->timestamp));
+               if (user->weak)
+                       str_append(str, "\tw");
+               str_append_c(str, '\n');
+               director_connection_send(conn, str_c(str));
 
                if (o_stream_get_buffer_used_size(conn->output) >= OUTBUF_FLUSH_THRESHOLD) {
                        if ((ret = o_stream_flush(conn->output)) <= 0) {