]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 7 Nov 2017 19:24:21 +0000 (21:24 +0200)
Optimizes the CPU usage.

src/director/director-connection.c

index 3f84cdeeca91b475f1b3b1942c990278b8684ede..a89cc52d19ab7242068119edad2f58d541116d92 100644 (file)
@@ -1982,23 +1982,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) {