summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorfilipe oliveira <filipecosta.90@gmail.com>2022-12-04 08:11:38 +0000
committerGitHub <noreply@github.com>2022-12-04 10:11:38 +0200
commit61c85a2b2081dffaf45eb8c6b7754b8d9a80c60d (patch)
tree5f2643bf348fe7da7d3f72d5ed0df39415fcdddc /src/util.h
parent155acef51ac7826ed294a4b61d891f1c7a9a40ac (diff)
downloadredis-61c85a2b2081dffaf45eb8c6b7754b8d9a80c60d.tar.gz
Speedup GEODIST with fixedpoint_d2string as an optimized version of snprintf %.4f (#11552)
GEODIST used snprintf("%.4f") for the reply using addReplyDoubleDistance, which was slow. This PR optimizes it without breaking compatibility by following the approach of ll2string with some changes to match the use case of distance and precision. I.e. we multiply it by 10000 format it as an integer, and then add a decimal point. This can achieve about 35% increase in the achievable ops/sec. Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index 4ff8a88e6..09d80e465 100644
--- a/src/util.h
+++ b/src/util.h
@@ -74,6 +74,7 @@ int string2ld(const char *s, size_t slen, long double *dp);
int string2d(const char *s, size_t slen, double *dp);
int trimDoubleString(char *buf, size_t len);
int d2string(char *buf, size_t len, double value);
+int fixedpoint_d2string(char *dst, size_t dstlen, double dvalue, int fractional_digits);
int ld2string(char *buf, size_t len, long double value, ld2string_mode mode);
int double2ll(double d, long long *out);
int yesnotoi(char *s);