# HG changeset patch # User Timo Sirainen # Date 1509802169 -7200 # Node ID 340fd327a9652ae437e9112197f0fb36986f313e # Parent 57e7fafb10c5272c319c3468f63f0d1589d7d785 director: Avoid str_printfa() in director_connection_send_users() Optimizes the CPU usage. diff -r 57e7fafb10c5 -r 340fd327a965 src/director/director-connection.c --- a/src/director/director-connection.c Sat Nov 04 02:17:55 2017 +0200 +++ b/src/director/director-connection.c Sat Nov 04 15:29:29 2017 +0200 @@ -1982,23 +1982,24 @@ 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) {