From 0d3a8c5f8b389e3f738d1f67c856ce1d5b9da1a9 Mon Sep 17 00:00:00 2001 From: Max Regan Date: Wed, 30 Nov 2022 21:05:29 -0500 Subject: [PATCH] Optimize scope lookup hotpath This yields a 25% overall performance increase --- src/scope.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scope.c b/src/scope.c index f622564..45e84b2 100644 --- a/src/scope.c +++ b/src/scope.c @@ -19,7 +19,9 @@ static struct ucl_object *ucl_scope_get_cell(struct ucl_scope *scope, const char *name) { FOREACH_LIST(scope->list, iter, item) { 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)) { 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); } 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) {