From 1eb819b90133280331769c2f2cb26266f6d3ab26 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 24 May 2007 00:52:03 +0000 Subject: [PATCH] fix to previous optimization in client_test --- examples/client_test.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 454313ce2..0d2e37229 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -149,8 +149,17 @@ void clear_home() char const* esc(char const* code) { - static char ret[20] = "\033["; #ifdef ANSI_TERMINAL_COLORS + // this is a silly optimization + // to avoid copying of strings + enum { num_strings = 20 }; + static char buf[num_strings][20]; + static int round_robin = 0; + char* ret = buf[round_robin]; + ++round_robin; + if (round_robin >= num_strings) round_robin = 0; + ret[0] = '\033'; + ret[1] = '['; int i = 2; int j = 0; while (code[j]) ret[i++] = code[j++];