diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-12-05 17:45:25 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-12-05 17:45:25 +0100 |
commit | 57ab1208c967f396c3e05eea7d0298fb347b6da2 (patch) | |
tree | 651a43ce367ef1992ce92438a7cca6da55454332 | |
parent | 37cb0c2a79e94d184c996ebe67bf46a07336aec8 (diff) | |
parent | 9f24ed8e0ddfa426c79f13c7091c39834c66780f (diff) | |
download | otp-57ab1208c967f396c3e05eea7d0298fb347b6da2.tar.gz otp-57ab1208c967f396c3e05eea7d0298fb347b6da2.tar.bz2 otp-57ab1208c967f396c3e05eea7d0298fb347b6da2.zip |
Merge branch 'egil/ets/use-internal-stack/OTP-12356'
* egil/ets/use-internal-stack/OTP-12356:
erts: Use internal stack for ets db_has_variable
-rw-r--r-- | erts/emulator/beam/erl_db_util.c | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/erts/emulator/beam/erl_db_util.c b/erts/emulator/beam/erl_db_util.c index b9fd3b208e..7eb80e3bb1 100644 --- a/erts/emulator/beam/erl_db_util.c +++ b/erts/emulator/beam/erl_db_util.c @@ -3254,34 +3254,38 @@ int db_is_variable(Eterm obj) /* return 1 if obj contains a variable or underscore */ /* return 0 if obj is fully ground */ -int db_has_variable(Eterm obj) -{ - switch(obj & _TAG_PRIMARY_MASK) { - case TAG_PRIMARY_LIST: { - while (is_list(obj)) { - if (db_has_variable(CAR(list_val(obj)))) +int db_has_variable(Eterm node) { + DECLARE_ESTACK(s); + + ESTACK_PUSH(s,node); + while (!ESTACK_ISEMPTY(s)) { + node = ESTACK_POP(s); + switch(node & _TAG_PRIMARY_MASK) { + case TAG_PRIMARY_LIST: + while (is_list(node)) { + ESTACK_PUSH(s,CAR(list_val(node))); + node = CDR(list_val(node)); + } + ESTACK_PUSH(s,node); /* Non wellformed list or [] */ + break; + case TAG_PRIMARY_BOXED: + if (is_tuple(node)) { + Eterm *tuple = tuple_val(node); + int arity = arityval(*tuple); + while(arity--) { + ESTACK_PUSH(s,*(++tuple)); + } + } + break; + case TAG_PRIMARY_IMMED1: + if (node == am_Underscore || db_is_variable(node) >= 0) { + DESTROY_ESTACK(s); return 1; - obj = CDR(list_val(obj)); - } - return(db_has_variable(obj)); /* Non wellformed list or [] */ - } - case TAG_PRIMARY_BOXED: - if (!is_tuple(obj)) { - return 0; - } else { - Eterm *tuple = tuple_val(obj); - int arity = arityval(*tuple++); - while(arity--) { - if (db_has_variable(*tuple)) - return 1; - tuple++; } - return(0); + break; } - case TAG_PRIMARY_IMMED1: - if (obj == am_Underscore || db_is_variable(obj) >= 0) - return 1; } + DESTROY_ESTACK(s); return 0; } |