From 5c09f0608f314a501debd1235b33c333dbe0c03e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 21 Feb 2016 11:46:34 +1100 Subject: [PATCH] Microoptimise ckdbq_process --- src/stratifier.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index fe8dcf99..766d3c97 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -6783,7 +6783,7 @@ static bool test_and_clear(bool *val, mutex_t *lock) static void ckdbq_process(ckpool_t *ckp, char *msg) { sdata_t *sdata = ckp->data; - size_t responselen = 0; + size_t responselen; char *buf = NULL; while (!buf) { @@ -6803,16 +6803,15 @@ static void ckdbq_process(ckpool_t *ckp, char *msg) /* Process any requests from ckdb that are heartbeat responses with * specific requests. */ - if (likely(buf)) - responselen = strlen(buf); - if (likely(responselen > 0)) { + responselen = strlen(buf); + if (likely(responselen > 1)) { char *response = alloca(responselen); int offset = 0; memset(response, 0, responselen); - if (sscanf(buf, "%*d.%*d.%c%n", response, &offset) > 0) { - strcpy(response+1, buf+offset); - if (safecmp(response, "ok")) { + if (likely(sscanf(buf, "%*d.%*d.%c%n", response, &offset) > 0)) { + strcpy(response + 1, buf + offset); + if (likely(safecmp(response, "ok"))) { char *cmd; cmd = response; @@ -6826,8 +6825,8 @@ static void ckdbq_process(ckpool_t *ckp, char *msg) LOGWARNING("Got ckdb failure response: %s", buf); } else LOGWARNING("Got bad ckdb response: %s", buf); - free(buf); } + free(buf); } static int transactions_by_jobid(sdata_t *sdata, const int64_t id)