mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Use sdscatfmt instead of sdscatprintf in module info
sdscatfmt is faster
This commit is contained in:
parent
d5c14c70b7
commit
1b4f888109
42
src/module.c
42
src/module.c
@ -4824,7 +4824,7 @@ int RM_InfoEndDictField(RedisModuleInfoCtx *ctx);
|
|||||||
int RM_InfoAddSection(RedisModuleInfoCtx *ctx, char *name) {
|
int RM_InfoAddSection(RedisModuleInfoCtx *ctx, char *name) {
|
||||||
sds full_name = sdsdup(ctx->module->name);
|
sds full_name = sdsdup(ctx->module->name);
|
||||||
if (name != NULL && strlen(name) > 0)
|
if (name != NULL && strlen(name) > 0)
|
||||||
full_name = sdscatprintf(full_name, "_%s", name);
|
full_name = sdscatfmt(full_name, "_%s", name);
|
||||||
|
|
||||||
/* Implicitly end dicts, instead of returning an error which is likely un checked. */
|
/* Implicitly end dicts, instead of returning an error which is likely un checked. */
|
||||||
if (ctx->in_dict_field)
|
if (ctx->in_dict_field)
|
||||||
@ -4843,7 +4843,7 @@ int RM_InfoAddSection(RedisModuleInfoCtx *ctx, char *name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctx->sections++) ctx->info = sdscat(ctx->info,"\r\n");
|
if (ctx->sections++) ctx->info = sdscat(ctx->info,"\r\n");
|
||||||
ctx->info = sdscatprintf(ctx->info, "# %s\r\n", full_name);
|
ctx->info = sdscatfmt(ctx->info, "# %S\r\n", full_name);
|
||||||
ctx->in_section = 1;
|
ctx->in_section = 1;
|
||||||
sdsfree(full_name);
|
sdsfree(full_name);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
@ -4858,7 +4858,7 @@ int RM_InfoBeginDictField(RedisModuleInfoCtx *ctx, char *name) {
|
|||||||
/* Implicitly end dicts, instead of returning an error which is likely un checked. */
|
/* Implicitly end dicts, instead of returning an error which is likely un checked. */
|
||||||
if (ctx->in_dict_field)
|
if (ctx->in_dict_field)
|
||||||
RM_InfoEndDictField(ctx);
|
RM_InfoEndDictField(ctx);
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s_%s:",
|
"%s_%s:",
|
||||||
ctx->module->name,
|
ctx->module->name,
|
||||||
name);
|
name);
|
||||||
@ -4873,7 +4873,7 @@ int RM_InfoEndDictField(RedisModuleInfoCtx *ctx) {
|
|||||||
/* trim the last ',' if found. */
|
/* trim the last ',' if found. */
|
||||||
if (ctx->info[sdslen(ctx->info)-1]==',')
|
if (ctx->info[sdslen(ctx->info)-1]==',')
|
||||||
sdsIncrLen(ctx->info, -1);
|
sdsIncrLen(ctx->info, -1);
|
||||||
ctx->info = sdscatprintf(ctx->info, "\r\n");
|
ctx->info = sdscat(ctx->info, "\r\n");
|
||||||
ctx->in_dict_field = 0;
|
ctx->in_dict_field = 0;
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
@ -4885,14 +4885,14 @@ int RM_InfoAddFieldString(RedisModuleInfoCtx *ctx, char *field, RedisModuleStrin
|
|||||||
if (!ctx->in_section)
|
if (!ctx->in_section)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
if (ctx->in_dict_field) {
|
if (ctx->in_dict_field) {
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s=%s,",
|
"%s=%S,",
|
||||||
field,
|
field,
|
||||||
(sds)value->ptr);
|
(sds)value->ptr);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s_%s:%s\r\n",
|
"%s_%s:%S\r\n",
|
||||||
ctx->module->name,
|
ctx->module->name,
|
||||||
field,
|
field,
|
||||||
(sds)value->ptr);
|
(sds)value->ptr);
|
||||||
@ -4903,13 +4903,13 @@ int RM_InfoAddFieldCString(RedisModuleInfoCtx *ctx, char *field, char *value) {
|
|||||||
if (!ctx->in_section)
|
if (!ctx->in_section)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
if (ctx->in_dict_field) {
|
if (ctx->in_dict_field) {
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s=%s,",
|
"%s=%s,",
|
||||||
field,
|
field,
|
||||||
value);
|
value);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s_%s:%s\r\n",
|
"%s_%s:%s\r\n",
|
||||||
ctx->module->name,
|
ctx->module->name,
|
||||||
field,
|
field,
|
||||||
@ -4939,14 +4939,14 @@ int RM_InfoAddFieldLongLong(RedisModuleInfoCtx *ctx, char *field, long long valu
|
|||||||
if (!ctx->in_section)
|
if (!ctx->in_section)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
if (ctx->in_dict_field) {
|
if (ctx->in_dict_field) {
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s=%lld,",
|
"%s=%I,",
|
||||||
field,
|
field,
|
||||||
value);
|
value);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s_%s:%lld\r\n",
|
"%s_%s:%I\r\n",
|
||||||
ctx->module->name,
|
ctx->module->name,
|
||||||
field,
|
field,
|
||||||
value);
|
value);
|
||||||
@ -4957,14 +4957,14 @@ int RM_InfoAddFieldULongLong(RedisModuleInfoCtx *ctx, char *field, unsigned long
|
|||||||
if (!ctx->in_section)
|
if (!ctx->in_section)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
if (ctx->in_dict_field) {
|
if (ctx->in_dict_field) {
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s=%llu,",
|
"%s=%U,",
|
||||||
field,
|
field,
|
||||||
value);
|
value);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
ctx->info = sdscatprintf(ctx->info,
|
ctx->info = sdscatfmt(ctx->info,
|
||||||
"%s_%s:%llu\r\n",
|
"%s_%s:%U\r\n",
|
||||||
ctx->module->name,
|
ctx->module->name,
|
||||||
field,
|
field,
|
||||||
value);
|
value);
|
||||||
@ -5712,9 +5712,9 @@ sds genModulesInfoString(sds info) {
|
|||||||
sds usedby = genModulesInfoStringRenderModulesList(module->usedby);
|
sds usedby = genModulesInfoStringRenderModulesList(module->usedby);
|
||||||
sds using = genModulesInfoStringRenderModulesList(module->using);
|
sds using = genModulesInfoStringRenderModulesList(module->using);
|
||||||
sds options = genModulesInfoStringRenderModuleOptions(module);
|
sds options = genModulesInfoStringRenderModuleOptions(module);
|
||||||
info = sdscatprintf(info,
|
info = sdscatfmt(info,
|
||||||
"module:name=%s,ver=%d,api=%d,filters=%d,"
|
"module:name=%S,ver=%i,api=%i,filters=%i,"
|
||||||
"usedby=%s,using=%s,options=%s\r\n",
|
"usedby=%S,using=%S,options=%S\r\n",
|
||||||
name, module->ver, module->apiver,
|
name, module->ver, module->apiver,
|
||||||
(int)listLength(module->filters), usedby, using, options);
|
(int)listLength(module->filters), usedby, using, options);
|
||||||
sdsfree(usedby);
|
sdsfree(usedby);
|
||||||
|
Loading…
Reference in New Issue
Block a user