Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
f6eb1747
Commit
f6eb1747
authored
May 22, 2010
by
Pieter Noordhuis
Browse files
move length housekeeping to a macro
parent
0f10458c
Changes
1
Hide whitespace changes
Inline
Side-by-side
ziplist.c
View file @
f6eb1747
...
...
@@ -25,6 +25,8 @@
#define ZIPLIST_BYTES(zl) (*((unsigned int*)(zl)))
#define ZIPLIST_LENGTH(zl) (*((zl)+sizeof(unsigned int)))
#define ZIPLIST_HEADER_SIZE (sizeof(unsigned int)+1)
#define ZIPLIST_INCR_LENGTH(zl,incr) { \
if (ZIPLIST_LENGTH(zl) < (ZIP_END-1)) ZIPLIST_LENGTH(zl)+=incr; }
/* Create a new empty ziplist. */
unsigned
char
*
ziplistNew
(
void
)
{
...
...
@@ -75,12 +77,10 @@ unsigned char *ziplistPush(unsigned char *zl, unsigned char *entry, unsigned int
p
=
zl
+
curlen
-
1
;
}
/* Increase length */
if
(
ZIPLIST_LENGTH
(
zl
)
<
ZIP_BIGLEN
)
ZIPLIST_LENGTH
(
zl
)
++
;
/* Write the entry */
p
+=
zipEncodeLength
(
p
,
elen
);
memcpy
(
p
,
entry
,
elen
);
ZIPLIST_INCR_LENGTH
(
zl
,
1
);
return
zl
;
}
...
...
@@ -103,7 +103,7 @@ unsigned char *ziplistPop(unsigned char *zl, sds *value, int where) {
/* Resize and update length */
zl
=
ziplistResize
(
zl
,
curlen
-
rlen
);
if
(
ZIPLIST_
LENGTH
(
zl
)
<
ZIP_BIGLEN
)
ZIPLIST
_LENGTH
(
zl
)
--
;
ZIPLIST_
INCR
_LENGTH
(
zl
,
-
1
)
;
return
zl
;
}
...
...
@@ -147,7 +147,7 @@ unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigne
/* Resize and update length */
zl
=
ziplistResize
(
zl
,
ZIPLIST_BYTES
(
zl
)
-
totlen
);
if
(
ZIPLIST_
LENGTH
(
zl
)
<
ZIP_BIGLEN
)
ZIPLIST
_LENGTH
(
zl
)
-=
deleted
;
ZIPLIST_
INCR
_LENGTH
(
zl
,
-
deleted
)
;
}
return
zl
;
}
...
...
@@ -165,7 +165,7 @@ unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p) {
/* Resize and update length */
zl
=
ziplistResize
(
zl
,
ZIPLIST_BYTES
(
zl
)
-
len
);
if
(
ZIPLIST_
LENGTH
(
zl
)
<
ZIP_BIGLEN
)
ZIPLIST
_LENGTH
(
zl
)
--
;
ZIPLIST_
INCR
_LENGTH
(
zl
,
-
1
)
;
/* Store new pointer to current element in p.
* This needs to be done because zl can change on realloc. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment