From cccfaf444e3b0a4eb0038dc43a4cb8d74b2fb590 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 17 Nov 2015 14:38:44 +0100 Subject: [PATCH] very slight but noticable performance improvement We avoid writing to "memory" just in order to check loop termination condition. While this looks like it makes really no difference, the profiler (valgrind's callgrind tool) tells it actually does. Also, wallclock time taken by time is consistently a bit lower than with the previous method. As it doesn't hurt anything (in terms of more complex code or so), I think the change is worth it. --- json_object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_object.c b/json_object.c index 7f085f3..4c4d04b 100644 --- a/json_object.c +++ b/json_object.c @@ -110,7 +110,7 @@ static int json_escape_str(struct printbuf *pb, const char *str, int len) { int pos = 0, start_offset = 0; unsigned char c; - while (len--) + while (pos < len) { c = str[pos]; switch(c)