Optimize scope lookup hotpath

This yields a 25% overall performance increase
This commit is contained in:
2022-11-30 21:05:29 -05:00
parent c38117e8a1
commit 0d3a8c5f8b

View File

@@ -19,7 +19,9 @@
static struct ucl_object *ucl_scope_get_cell(struct ucl_scope *scope, const char *name) { static struct ucl_object *ucl_scope_get_cell(struct ucl_scope *scope, const char *name) {
FOREACH_LIST(scope->list, iter, item) { FOREACH_LIST(scope->list, iter, item) {
assert(item->type == UCL_TYPE_CELL); assert(item->type == UCL_TYPE_CELL);
const char *item_name = ucl_list_nth(item, NAME_POSITION)->string; // This code is very hot. "I know what I'm doing" and skip the error
// checking.
const char *item_name = item->cell.car->string;
if (ucl_strequal(name, item_name)) { if (ucl_strequal(name, item_name)) {
return item; return item;
} }
@@ -39,7 +41,6 @@ struct ucl_object *ucl_scope_get(struct ucl *state, struct ucl_scope *scope, con
cell = ucl_scope_get_cell(scope, name); cell = ucl_scope_get_cell(scope, name);
} }
return ucl_list_nth(cell, DATA_POSITION); return ucl_list_nth(cell, DATA_POSITION);
} }
void ucl_scope_put(struct ucl *state, struct ucl_scope *scope, const char *name, struct ucl_object *obj) { void ucl_scope_put(struct ucl *state, struct ucl_scope *scope, const char *name, struct ucl_object *obj) {