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
96224f75
You need to sign in or sign up before continuing.
Commit
96224f75
authored
Sep 06, 2016
by
antirez
Browse files
dict.c clustered slot prealloc.
parent
976a7d23
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dict.c
View file @
96224f75
...
...
@@ -60,7 +60,7 @@
* prevented: a hash table is still allowed to grow if the ratio between
* the number of elements and the buckets > dict_force_resize_ratio. */
static
int
dict_can_resize
=
1
;
static
unsigned
int
dict_resize_ratio
=
2
0
;
static
unsigned
int
dict_resize_ratio
=
1
0
;
static
unsigned
int
dict_force_resize_ratio
=
60
;
/* -------------------------- private prototypes ---------------------------- */
...
...
@@ -153,14 +153,20 @@ dictEntry *dictPushEntry(dictEntryVector **table, unsigned int idx, const void *
dictEntry
*
he
;
if
(
dv
==
NULL
)
{
dv
=
table
[
idx
]
=
zmalloc
(
sizeof
(
dictEntryVector
)
+
sizeof
(
dictEntry
));
int
initlen
=
dict_resize_ratio
/
4
;
if
(
initlen
==
0
)
initlen
=
1
;
dv
=
table
[
idx
]
=
zcalloc
(
sizeof
(
dictEntryVector
)
+
sizeof
(
dictEntry
)
*
initlen
);
dv
->
used
=
1
;
dv
->
free
=
0
;
dv
->
free
=
initlen
-
1
;
he
=
dv
->
entry
;
}
else
if
(
dv
->
free
==
0
)
{
dv
=
table
[
idx
]
=
zrealloc
(
table
[
idx
],
sizeof
(
dictEntryVector
)
+
sizeof
(
dictEntry
)
*
(
dv
->
used
+
1
));
int
newlen
=
(
dv
->
used
+
dv
->
free
)
*
2
;
dv
=
table
[
idx
]
=
zrealloc
(
table
[
idx
],
sizeof
(
dictEntryVector
)
+
sizeof
(
dictEntry
)
*
newlen
);
he
=
dv
->
entry
+
dv
->
used
;
dv
->
used
++
;
dv
->
free
=
newlen
-
dv
->
used
;
memset
(
dv
->
entry
+
dv
->
used
,
0
,
sizeof
(
dictEntry
)
*
dv
->
free
);
}
else
{
uint32_t
entries
=
dv
->
used
+
dv
->
free
;
uint32_t
j
;
...
...
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