From adc76b96aae1da21a25a330143c693ae491ccccf Mon Sep 17 00:00:00 2001 From: Ariel Shtul Date: Sun, 28 Apr 2024 14:40:58 +0300 Subject: [PATCH] remove lpAssertValidEntry from listpack functions --- src/listpack.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/listpack.c b/src/listpack.c index ad2fe9d9d4..f2d2981a76 100644 --- a/src/listpack.c +++ b/src/listpack.c @@ -137,8 +137,6 @@ assert((p) >= (lp)+LP_HDR_SIZE && (p)+(len) < (lp)+lpGetTotalBytes((lp))); \ } while (0) -static inline void lpAssertValidEntry(unsigned char* lp, size_t lpbytes, unsigned char *p); - /* Don't let listpacks grow over 1GB in any case, don't wanna risk overflow in * Total Bytes header field */ #define LISTPACK_MAX_SAFETY_SIZE (1<<30) @@ -475,7 +473,6 @@ unsigned char *lpNext(unsigned char *lp, unsigned char *p) { assert(p); p = lpSkip(p); if (p[0] == LP_EOF) return NULL; - lpAssertValidEntry(lp, lpBytes(lp), p); return p; } @@ -489,7 +486,6 @@ unsigned char *lpPrev(unsigned char *lp, unsigned char *p) { uint64_t prevlen = lpDecodeBacklen(p); prevlen += lpEncodeBacklen(NULL,prevlen); p -= prevlen-1; /* Seek the first byte of the previous entry. */ - lpAssertValidEntry(lp, lpBytes(lp), p); return p; } @@ -498,7 +494,6 @@ unsigned char *lpPrev(unsigned char *lp, unsigned char *p) { unsigned char *lpFirst(unsigned char *lp) { unsigned char *p = lp + LP_HDR_SIZE; /* Skip the header. */ if (p[0] == LP_EOF) return NULL; - lpAssertValidEntry(lp, lpBytes(lp), p); return p; } @@ -731,17 +726,12 @@ unsigned char *lpFind(unsigned char *lp, unsigned char *p, unsigned char *s, } else { /* Skip entry */ skipcnt--; - - /* Move to next entry, avoid use `lpNext` due to `lpAssertValidEntry` in - * `lpNext` will call `lpBytes`, will cause performance degradation */ p = lpSkip(p); } /* The next call to lpGetWithSize could read at most 8 bytes past `p` * We use the slower validation call only when necessary. */ - if (p + 8 >= lp + lp_bytes) - lpAssertValidEntry(lp, lp_bytes, p); - else + if (p + 8 < lp + lp_bytes) assert(p >= lp + LP_HDR_SIZE && p < lp + lp_bytes); if (p[0] == LP_EOF) break; } @@ -1013,7 +1003,6 @@ unsigned char *lpDeleteRangeWithEntry(unsigned char *lp, unsigned char **p, unsi deleted++; tail = lpSkip(tail); if (tail[0] == LP_EOF) break; - lpAssertValidEntry(lp, bytes, tail); } /* Store the offset of the element 'first', so that we can obtain its @@ -1337,11 +1326,6 @@ int lpValidateNext(unsigned char *lp, unsigned char **pp, size_t lpbytes) { #undef OUT_OF_RANGE } -/* Validate that the entry doesn't reach outside the listpack allocation. */ -static inline void lpAssertValidEntry(unsigned char* lp, size_t lpbytes, unsigned char *p) { - assert(lpValidateNext(lp, &p, lpbytes)); -} - /* Validate the integrity of the data structure. * when `deep` is 0, only the integrity of the header is validated. * when `deep` is 1, we scan all the entries one by one. */