summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2022-04-17 17:16:46 +0300
committerGitHub <noreply@github.com>2022-04-17 17:16:46 +0300
commit0c4733c8d7c50e0b0dc3373733fddfff3f62dda0 (patch)
tree5ecd20be1f6f9397539d42558b84f74a0800d87a /src/util.h
parentf49ff156ecd62aee104cff9f88fb62948575e6b0 (diff)
downloadredis-0c4733c8d7c50e0b0dc3373733fddfff3f62dda0.tar.gz
Optimize integer zset scores in listpack (converting to string and back) (#10486)
When the score doesn't have fractional part, and can be stored as an integer, we use the integer capabilities of listpack to store it, rather than convert it to string. This already existed before this PR (lpInsert dose that conversion implicitly). But to do that, we would have first converted the score from double to string (calling `d2string`), then pass the string to `lpAppend` which identified it as being an integer and convert it back to an int. Now, instead of converting it to a string, we store it using lpAppendInteger`. Unrelated: --- * Fix the double2ll range check (negative and positive ranges, and also the comparison operands were slightly off. but also, the range could be made much larger, see comment). * Unify the double to string conversion code in rdb.c with the one in util.c * Small optimization in lpStringToInt64, don't attempt to convert strings that are obviously too long. Benchmark; --- Up to 20% improvement in certain tight loops doing zzlInsert with large integers. (if listpack is pre-allocated to avoid realloc, and insertion is sorted from largest to smaller)
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 5ea71fecd..0515f1a83 100644
--- a/src/util.h
+++ b/src/util.h
@@ -75,6 +75,7 @@ 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 ld2string(char *buf, size_t len, long double value, ld2string_mode mode);
+int double2ll(double d, long long *out);
int yesnotoi(char *s);
sds getAbsolutePath(char *filename);
long getTimeZone(void);