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
d292a516
Commit
d292a516
authored
Mar 14, 2019
by
antirez
Browse files
Improve comments after merging #5834.
parent
0cce98f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
d292a516
...
@@ -523,12 +523,17 @@ void RedisModuleCommandDispatcher(client *c) {
...
@@ -523,12 +523,17 @@ void RedisModuleCommandDispatcher(client *c) {
moduleFreeContext
(
&
ctx
);
moduleFreeContext
(
&
ctx
);
/* In some cases processMultibulkBuffer uses sdsMakeRoomFor to
/* In some cases processMultibulkBuffer uses sdsMakeRoomFor to
* expand the querybuf, but later in some cases it uses that query
* expand the query buffer, and in order to avoid a big object copy
* buffer as is for an argv element (see "Optimization"), which means
* the query buffer SDS may be used directly as the SDS string backing
* that the sds in argv may have a lot of wasted space, and then in case
* the client argument vectors: sometimes this will result in the SDS
* modules keep that argv RedisString inside their data structure, this
* string having unused space at the end. Later if a module takes ownership
* space waste will remain for long (until restarted from rdb). */
* of the RedisString, such space will be wasted forever. Inside the
* Redis core this is not a problem because tryObjectEncoding() is called
* before storing strings in the key space. Here we need to do it
* for the module. */
for
(
int
i
=
0
;
i
<
c
->
argc
;
i
++
)
{
for
(
int
i
=
0
;
i
<
c
->
argc
;
i
++
)
{
/* Only do the work if the module took ownership of the object:
* in that case the refcount is no longer 1. */
if
(
c
->
argv
[
i
]
->
refcount
>
1
)
if
(
c
->
argv
[
i
]
->
refcount
>
1
)
trimStringObjectIfNeeded
(
c
->
argv
[
i
]);
trimStringObjectIfNeeded
(
c
->
argv
[
i
]);
}
}
...
...
src/object.c
View file @
d292a516
...
@@ -415,10 +415,11 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
...
@@ -415,10 +415,11 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
}
}
}
}
/* Optimize the SDS string inside the string object to require little space,
* in case there is more than 10% of free space at the end of the SDS
* string. This happens because SDS strings tend to overallocate to avoid
* wasting too much time in allocations when appending to the string. */
void
trimStringObjectIfNeeded
(
robj
*
o
)
{
void
trimStringObjectIfNeeded
(
robj
*
o
)
{
/* Optimize the SDS string inside the string object to require
* little space, in case there is more than 10% of free space
* at the end of the SDS string. */
if
(
o
->
encoding
==
OBJ_ENCODING_RAW
&&
if
(
o
->
encoding
==
OBJ_ENCODING_RAW
&&
sdsavail
(
o
->
ptr
)
>
sdslen
(
o
->
ptr
)
/
10
)
sdsavail
(
o
->
ptr
)
>
sdslen
(
o
->
ptr
)
/
10
)
{
{
...
...
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