mirror of
https://github.com/fluencelabs/redis
synced 2025-03-22 10:30:49 +00:00
optimized amFree even further
This commit is contained in:
parent
46b07cbb5c
commit
137fd86a61
13
src/module.c
13
src/module.c
@ -585,12 +585,17 @@ void autoMemoryFreed(RedisModuleCtx *ctx, int type, void *ptr) {
|
|||||||
ctx->amqueue[j].ptr == ptr)
|
ctx->amqueue[j].ptr == ptr)
|
||||||
{
|
{
|
||||||
ctx->amqueue[j].type = REDISMODULE_AM_FREED;
|
ctx->amqueue[j].type = REDISMODULE_AM_FREED;
|
||||||
/* Optimization: if this is the last element, we can
|
|
||||||
* reuse it. */
|
/* Switch the freed element and the top element, to avoid growing
|
||||||
if (j == ctx->amqueue_used-1) ctx->amqueue_used--;
|
* the queue unnecessarily if we allocate/free in a loop */
|
||||||
|
if (j != ctx->amqueue_used-1) {
|
||||||
|
ctx->amqueue[j] = ctx->amqueue[ctx->amqueue_used-1];
|
||||||
|
}
|
||||||
|
/* Reduce the size of the queue because we either moved the top
|
||||||
|
* element elsewhere or freed it */
|
||||||
|
ctx->amqueue_used--;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user