changeset 22646:340fd327a965

director: Avoid str_printfa() in director_connection_send_users() Optimizes the CPU usage.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sat, 04 Nov 2017 15:29:29 +0200
parents 57e7fafb10c5
children 641236fac254
files src/director/director-connection.c
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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) {