projects
/
redis.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Contextualize comment.
[redis.git]
/
src
/
zipmap.c
diff --git
a/src/zipmap.c
b/src/zipmap.c
index 9f663fda0d4906be333c1973cbf07a0cba656126..1f11fd429ea016a303a04cf6d78645bb1d8fa60f 100644
(file)
--- a/
src/zipmap.c
+++ b/
src/zipmap.c
@@
-80,6
+80,7
@@
#include <string.h>
#include <assert.h>
#include "zmalloc.h"
#include <string.h>
#include <assert.h>
#include "zmalloc.h"
+#include "endianconv.h"
#define ZIPMAP_BIGLEN 254
#define ZIPMAP_END 255
#define ZIPMAP_BIGLEN 254
#define ZIPMAP_END 255
@@
-108,6
+109,7
@@
static unsigned int zipmapDecodeLength(unsigned char *p) {
if (len < ZIPMAP_BIGLEN) return len;
memcpy(&len,p+1,sizeof(unsigned int));
if (len < ZIPMAP_BIGLEN) return len;
memcpy(&len,p+1,sizeof(unsigned int));
+ memrev32ifbe(&len);
return len;
}
return len;
}
@@
-123,6
+125,7
@@
static unsigned int zipmapEncodeLength(unsigned char *p, unsigned int len) {
} else {
p[0] = ZIPMAP_BIGLEN;
memcpy(p+1,&len,sizeof(len));
} else {
p[0] = ZIPMAP_BIGLEN;
memcpy(p+1,&len,sizeof(len));
+ memrev32ifbe(p+1);
return 1+sizeof(len);
}
}
return 1+sizeof(len);
}
}
@@
-144,7
+147,7
@@
static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, uns
/* Match or skip the key */
l = zipmapDecodeLength(p);
llen = zipmapEncodeLength(NULL,l);
/* Match or skip the key */
l = zipmapDecodeLength(p);
llen = zipmapEncodeLength(NULL,l);
- if (k == NULL && l == klen && !memcmp(p+llen,key,l)) {
+ if (k
ey != 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) {
/* Only return when the user doesn't care
* for the total length of the zipmap. */
if (totlen != NULL) {
@@
-295,7
+298,7
@@
unsigned char *zipmapDel(unsigned char *zm, unsigned char *key, unsigned int kle
return zm;
}
return zm;
}
-/* Call
it before to iterate trought
elements via zipmapNext() */
+/* Call
before iterating through
elements via zipmapNext() */
unsigned char *zipmapRewind(unsigned char *zm) {
return zm+1;
}
unsigned char *zipmapRewind(unsigned char *zm) {
return zm+1;
}
@@
-364,14
+367,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) {
* 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;
void zipmapRepr(unsigned char *p) {
unsigned int l;
@@
-405,7
+406,6
@@
void zipmapRepr(unsigned char *p) {
printf("\n");
}
printf("\n");
}
-#ifdef ZIPMAP_TEST_MAIN
int main(void) {
unsigned char *zm;
int main(void) {
unsigned char *zm;
@@
-452,7
+452,7
@@
int main(void) {
vlen, vlen, value);
}
}
vlen, vlen, value);
}
}
- printf("\nIterate t
rought
elements:\n");
+ printf("\nIterate t
hrough
elements:\n");
{
unsigned char *i = zipmapRewind(zm);
unsigned char *key, *value;
{
unsigned char *i = zipmapRewind(zm);
unsigned char *key, *value;