mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Improve comments after merging #5834.
This commit is contained in:
parent
0cce98f2f9
commit
d292a51618
15
src/module.c
15
src/module.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]);
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user