summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-02-28 14:48:49 +0100
committerantirez <antirez@gmail.com>2011-02-28 14:48:49 +0100
commitd4fb9f4144e72a7918e477c22a6c2a75d9c3c30d (patch)
treee1f9c6f1d6cf17f3271685d2e9c5ef56c164fc18
parent2cc993655f2c7da5f893e6f628f6c34f6204c3d3 (diff)
downloadredis-d4fb9f4144e72a7918e477c22a6c2a75d9c3c30d.tar.gz
encoded types API to get blob length
-rw-r--r--src/intset.c5
-rw-r--r--src/intset.h1
-rw-r--r--src/ziplist.c4
-rw-r--r--src/ziplist.h2
-rw-r--r--src/zipmap.c13
5 files changed, 14 insertions, 11 deletions
diff --git a/src/intset.c b/src/intset.c
index bfd3307d2..13bd220e7 100644
--- a/src/intset.c
+++ b/src/intset.c
@@ -222,6 +222,11 @@ uint32_t intsetLen(intset *is) {
return is->length;
}
+/* Return intset blob size in bytes. */
+size_t intsetBlobLen(intset *is) {
+ return sizeof(intset)+is->length*is->encoding;
+}
+
#ifdef INTSET_TEST_MAIN
#include <sys/time.h>
diff --git a/src/intset.h b/src/intset.h
index 10d49d2e0..ee4b91fa9 100644
--- a/src/intset.h
+++ b/src/intset.h
@@ -15,5 +15,6 @@ uint8_t intsetFind(intset *is, int64_t value);
int64_t intsetRandom(intset *is);
uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value);
uint32_t intsetLen(intset *is);
+size_t intsetBlobLen(intset *is);
#endif // __INTSET_H
diff --git a/src/ziplist.c b/src/ziplist.c
index 233fabefe..524f72388 100644
--- a/src/ziplist.c
+++ b/src/ziplist.c
@@ -730,8 +730,8 @@ unsigned int ziplistLen(unsigned char *zl) {
return len;
}
-/* Return size in bytes of ziplist. */
-unsigned int ziplistSize(unsigned char *zl) {
+/* Return ziplist blob size in bytes. */
+size_t ziplistBlobLen(unsigned char *zl) {
return ZIPLIST_BYTES(zl);
}
diff --git a/src/ziplist.h b/src/ziplist.h
index 311257256..a07b84404 100644
--- a/src/ziplist.h
+++ b/src/ziplist.h
@@ -12,4 +12,4 @@ unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p);
unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num);
unsigned int ziplistCompare(unsigned char *p, unsigned char *s, unsigned int slen);
unsigned int ziplistLen(unsigned char *zl);
-unsigned int ziplistSize(unsigned char *zl);
+size_t ziplistBlobLen(unsigned char *zl);
diff --git a/src/zipmap.c b/src/zipmap.c
index 9f663fda0..693db7b93 100644
--- a/src/zipmap.c
+++ b/src/zipmap.c
@@ -144,7 +144,7 @@ static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, uns
/* Match or skip the key */
l = zipmapDecodeLength(p);
llen = zipmapEncodeLength(NULL,l);
- if (k == NULL && l == klen && !memcmp(p+llen,key,l)) {
+ if (key != NULL && k == NULL && l == klen && !memcmp(p+llen,key,l)) {
/* Only return when the user doesn't care
* for the total length of the zipmap. */
if (totlen != NULL) {
@@ -364,14 +364,12 @@ unsigned int zipmapLen(unsigned char *zm) {
* the zipmap on disk (or everywhere is needed) just writing the returned
* amount of bytes of the C array starting at the zipmap pointer. */
size_t zipmapBlobLen(unsigned char *zm) {
- unsigned char *p = zipmapRewind(zm);
- unsigned char *old = p;
- while((p = zipmapNext(p,NULL,NULL,NULL,NULL)) != NULL) {
- old = p;
- }
- return (old-zm)+1;
+ unsigned int totlen;
+ zipmapLookupRaw(zm,NULL,0,&totlen);
+ return totlen;
}
+#ifdef ZIPMAP_TEST_MAIN
void zipmapRepr(unsigned char *p) {
unsigned int l;
@@ -405,7 +403,6 @@ void zipmapRepr(unsigned char *p) {
printf("\n");
}
-#ifdef ZIPMAP_TEST_MAIN
int main(void) {
unsigned char *zm;