summaryrefslogtreecommitdiff
path: root/py/scope.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-10-27 22:41:21 +1100
committerDamien George <damien.p.george@gmail.com>2018-10-28 00:38:18 +1100
commite328a5d4693f9e4a03b296e7a9a7af6660d99515 (patch)
tree178e4fbab5adbd14fb3c03e9754f044699626fc8 /py/scope.c
parentba92c798414d5dcf76ac7bfd153884873cceca08 (diff)
py/scope: Optimise scope_find_or_add_id to not need "added" arg.
Taking the address of a local variable is mildly expensive, in code size and stack usage. So optimise scope_find_or_add_id() to not need to take a pointer to the "added" variable, and instead take the kind to use for newly added identifiers.
Diffstat (limited to 'py/scope.c')
-rw-r--r--py/scope.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/py/scope.c b/py/scope.c
index 8adb85b80..d996731f8 100644
--- a/py/scope.c
+++ b/py/scope.c
@@ -64,10 +64,9 @@ void scope_free(scope_t *scope) {
m_del(scope_t, scope, 1);
}
-id_info_t *scope_find_or_add_id(scope_t *scope, qstr qst, bool *added) {
+id_info_t *scope_find_or_add_id(scope_t *scope, qstr qst, scope_kind_t kind) {
id_info_t *id_info = scope_find(scope, qst);
if (id_info != NULL) {
- *added = false;
return id_info;
}
@@ -82,11 +81,10 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qst, bool *added) {
// handled by the compiler because it adds arguments before compiling the body
id_info = &scope->id_info[scope->id_info_len++];
- id_info->kind = 0;
+ id_info->kind = kind;
id_info->flags = 0;
id_info->local_num = 0;
id_info->qst = qst;
- *added = true;
return id_info;
}
@@ -110,9 +108,8 @@ STATIC void scope_close_over_in_parents(scope_t *scope, qstr qst) {
assert(scope->parent != NULL); // we should have at least 1 parent
for (scope_t *s = scope->parent;; s = s->parent) {
assert(s->parent != NULL); // we should not get to the outer scope
- bool added;
- id_info_t *id = scope_find_or_add_id(s, qst, &added);
- if (added) {
+ id_info_t *id = scope_find_or_add_id(s, qst, ID_INFO_KIND_UNDECIDED);
+ if (id->kind == ID_INFO_KIND_UNDECIDED) {
// variable not previously declared in this scope, so declare it as free and keep searching parents
id->kind = ID_INFO_KIND_FREE;
} else {