From 208a1d011ebac2c0dfc3850b2b5265cfe89ada71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sat, 8 Dec 2018 11:27:39 +0200 Subject: [PATCH] Pre-allocate return value in get_canonical Since we know the worst-case size of a canonical statement is the size of the query string, we can reduce the number of memory allocations to one in the get_canonical function. --- server/core/modutil.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/server/core/modutil.cc b/server/core/modutil.cc index a4c236a74..b1eaecb8c 100644 --- a/server/core/modutil.cc +++ b/server/core/modutil.cc @@ -1367,6 +1367,7 @@ namespace maxscale std::string get_canonical(GWBUF* querybuf) { std::string rval; + rval.reserve(gwbuf_length(querybuf) - MYSQL_HEADER_LEN + 1); mxs::Buffer buf(querybuf); enum state