Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
400aea2b
Commit
400aea2b
authored
Jun 13, 2010
by
Pieter Noordhuis
Browse files
expand the dictionary of the target set to the right size when converting from intset
parent
273f6169
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
400aea2b
...
@@ -4193,6 +4193,7 @@ static int rdbLoadDoubleValue(FILE *fp, double *val) {
...
@@ -4193,6 +4193,7 @@ static int rdbLoadDoubleValue(FILE *fp, double *val) {
static robj *rdbLoadObject(int type, FILE *fp) {
static robj *rdbLoadObject(int type, FILE *fp) {
robj *o, *ele, *dec;
robj *o, *ele, *dec;
size_t len;
size_t len;
unsigned int i;
redisLog(REDIS_DEBUG,"LOADING OBJECT %d (at %d)\n",type,ftell(fp));
redisLog(REDIS_DEBUG,"LOADING OBJECT %d (at %d)\n",type,ftell(fp));
if (type == REDIS_STRING) {
if (type == REDIS_STRING) {
...
@@ -4247,7 +4248,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
...
@@ -4247,7 +4248,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
}
}
/* Load every single element of the list/set */
/* Load every single element of the list/set */
while(len--
) {
for (i = 0; i < len; i++
) {
long long llval;
long long llval;
if ((ele = rdbLoadEncodedStringObject(fp)) == NULL) return NULL;
if ((ele = rdbLoadEncodedStringObject(fp)) == NULL) return NULL;
ele = tryObjectEncoding(ele);
ele = tryObjectEncoding(ele);
...
@@ -4258,6 +4259,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
...
@@ -4258,6 +4259,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
o->ptr = intsetAdd(o->ptr,llval,NULL);
o->ptr = intsetAdd(o->ptr,llval,NULL);
} else {
} else {
setTypeConvert(o,REDIS_ENCODING_HT);
setTypeConvert(o,REDIS_ENCODING_HT);
dictExpand(o->ptr,len);
}
}
}
}
...
@@ -5668,6 +5670,9 @@ static unsigned long setTypeSize(robj *subject) {
...
@@ -5668,6 +5670,9 @@ static unsigned long setTypeSize(robj *subject) {
}
}
}
}
/* Convert the set to specified encoding. The resulting dict (when converting
* to a hashtable) is presized to hold the number of elements in the original
* set. */
static void setTypeConvert(robj *subject, int enc) {
static void setTypeConvert(robj *subject, int enc) {
setIterator *si;
setIterator *si;
robj *element;
robj *element;
...
@@ -5675,6 +5680,8 @@ static void setTypeConvert(robj *subject, int enc) {
...
@@ -5675,6 +5680,8 @@ static void setTypeConvert(robj *subject, int enc) {
if (enc == REDIS_ENCODING_HT) {
if (enc == REDIS_ENCODING_HT) {
dict *d = dictCreate(&setDictType,NULL);
dict *d = dictCreate(&setDictType,NULL);
/* Presize the dict to avoid rehashing */
dictExpand(d,intsetLen(subject->ptr));
/* setTypeGet returns a robj with incremented refcount */
/* setTypeGet returns a robj with incremented refcount */
si = setTypeInitIterator(subject);
si = setTypeInitIterator(subject);
...
...
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