Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
7b1f85c0
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7b1f85c0
编写于
5月 29, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use simpler encoding for the length of the previous entry
上级
1ce81fa5
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
36 addition
and
7 deletion
+36
-7
ziplist.c
ziplist.c
+36
-7
未找到文件。
ziplist.c
浏览文件 @
7b1f85c0
...
...
@@ -133,12 +133,41 @@ static unsigned int zipEncodeLength(unsigned char *p, char encoding, unsigned in
return
len
;
}
/* Decode the length of the previous element stored at "p". */
static
unsigned
int
zipPrevDecodeLength
(
unsigned
char
*
p
,
unsigned
int
*
lensize
)
{
unsigned
int
len
=
*
p
;
if
(
len
<
ZIP_BIGLEN
)
{
if
(
lensize
)
*
lensize
=
1
;
}
else
{
if
(
lensize
)
*
lensize
=
1
+
sizeof
(
len
);
memcpy
(
&
len
,
p
+
1
,
sizeof
(
len
));
}
return
len
;
}
/* Encode the length of the previous entry and write it to "p". Return the
* number of bytes needed to encode this length if "p" is NULL. */
static
unsigned
int
zipPrevEncodeLength
(
unsigned
char
*
p
,
unsigned
int
len
)
{
if
(
p
==
NULL
)
{
return
(
len
<
ZIP_BIGLEN
)
?
1
:
sizeof
(
len
)
+
1
;
}
else
{
if
(
len
<
ZIP_BIGLEN
)
{
p
[
0
]
=
len
;
return
1
;
}
else
{
p
[
0
]
=
ZIP_BIGLEN
;
memcpy
(
p
+
1
,
&
len
,
sizeof
(
len
));
return
1
+
sizeof
(
len
);
}
}
}
/* Return the difference in number of bytes needed to store the new length
* "len" on the entry pointed to by "p". */
static
int
zipPrevLenByteDiff
(
unsigned
char
*
p
,
unsigned
int
len
)
{
unsigned
int
prevlensize
;
zipDecodeLength
(
p
,
&
prevlensize
);
return
zip
EncodeLength
(
NULL
,
ZIP_ENC_RAW
,
len
)
-
prevlensize
;
zip
Prev
DecodeLength
(
p
,
&
prevlensize
);
return
zip
PrevEncodeLength
(
NULL
,
len
)
-
prevlensize
;
}
/* Check if string pointed to by 'entry' can be encoded as an integer.
...
...
@@ -206,7 +235,7 @@ static long long zipLoadInteger(unsigned char *p, char encoding) {
/* Return a struct with all information about an entry. */
static
zlentry
zipEntry
(
unsigned
char
*
p
)
{
zlentry
e
;
e
.
prevrawlen
=
zipDecodeLength
(
p
,
&
e
.
prevrawlensize
);
e
.
prevrawlen
=
zip
Prev
DecodeLength
(
p
,
&
e
.
prevrawlensize
);
e
.
len
=
zipDecodeLength
(
p
+
e
.
prevrawlensize
,
&
e
.
lensize
);
e
.
headersize
=
e
.
prevrawlensize
+
e
.
lensize
;
e
.
encoding
=
ZIP_ENCODING
(
p
+
e
.
prevrawlensize
);
...
...
@@ -257,7 +286,7 @@ static unsigned char *__ziplistDelete(unsigned char *zl, unsigned char *p, int n
* prevlen. Note that we can always store this length because
* it was previously stored by an entry that is being deleted. */
nextdiff
=
zipPrevLenByteDiff
(
p
,
first
.
prevrawlen
);
zip
EncodeLength
(
p
-
nextdiff
,
ZIP_ENC_RAW
,
first
.
prevrawlen
);
zip
PrevEncodeLength
(
p
-
nextdiff
,
first
.
prevrawlen
);
/* Update offset for tail */
ZIPLIST_TAIL_OFFSET
(
zl
)
-=
totlen
+
nextdiff
;
...
...
@@ -305,7 +334,7 @@ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsig
/* We need space for both the length of the previous entry and
* the length of the payload. */
reqlen
+=
zip
EncodeLength
(
NULL
,
ZIP_ENC_RAW
,
prevlen
);
reqlen
+=
zip
PrevEncodeLength
(
NULL
,
prevlen
);
reqlen
+=
zipEncodeLength
(
NULL
,
encoding
,
slen
);
/* When the insert position is not equal to the tail, we need to
...
...
@@ -323,7 +352,7 @@ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsig
/* Subtract one because of the ZIP_END bytes */
memmove
(
p
+
reqlen
,
p
-
nextdiff
,
curlen
-
offset
-
1
+
nextdiff
);
/* Encode this entry's raw length in the next entry. */
zip
EncodeLength
(
p
+
reqlen
,
ZIP_ENC_RAW
,
reqlen
);
zip
PrevEncodeLength
(
p
+
reqlen
,
reqlen
);
/* Update offset for tail */
ZIPLIST_TAIL_OFFSET
(
zl
)
+=
reqlen
+
nextdiff
;
}
else
{
...
...
@@ -332,7 +361,7 @@ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsig
}
/* Write the entry */
p
+=
zip
EncodeLength
(
p
,
ZIP_ENC_RAW
,
prevlen
);
p
+=
zip
PrevEncodeLength
(
p
,
prevlen
);
p
+=
zipEncodeLength
(
p
,
encoding
,
slen
);
if
(
encoding
!=
ZIP_ENC_RAW
)
{
zipSaveInteger
(
p
,
value
,
encoding
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录