From 0678c088360752f332752c3eaec551280151c29c Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Sun, 6 Jan 2019 09:16:07 -0500 Subject: Remove alength array method in favor of accessing table_size directly. --- ChangeLog | 21 +++++++++++++++++++++ array.c | 10 ---------- awk.h | 42 +++++++++++++++++++----------------------- cint_array.c | 1 - gawkapi.c | 2 +- int_array.c | 1 - str_array.c | 2 -- symbol.c | 4 ++-- 8 files changed, 43 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a22e9c7..e713dd48 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2019-01-06 Andrew J. Schorr + + Remove pointless alength macro/method that uses a needless + function call indirection to access the table_size value. + + * awk.h (alength, alength_ind): Remove these defines, and also renumber + the array_funcs items after that, and use the _ind define to + define instead of repeating the hardcoded numeric value. + (NUM_AFUNCS): Remove unused define. + (assoc_length): Redefine to access table_size directly. + (null_length): Remove prototype. + * array.c (null_array_func): Remove null_length entry. + (null_length): Remove obsolete function. + * cint_array.c (cint_array_func): Remove null_length entry. + * int_array.c (int_array_func): Remove null_length entry. + * str_array.c (str_array_func, env_array_func): Remove null_length + entry. + * gawkapi.c (api_flatten_array_typed): Use the assoc_empty macro to + check for an empty array instead of comparing table_size to 0. + * symbol.c (lookup, check_param_names): Ditto. + 2018-12-21 Arnold D. Robbins * configure.ac: Remove -O only if .developing has 'debug' in it. diff --git a/array.c b/array.c index aa52f3a1..d8fbab33 100644 --- a/array.c +++ b/array.c @@ -40,7 +40,6 @@ static NODE **null_dump(NODE *symbol, NODE *subs); static afunc_t null_array_func[] = { (afunc_t) 0, (afunc_t) 0, - null_length, null_lookup, null_afunc, null_afunc, @@ -150,15 +149,6 @@ null_lookup(NODE *symbol, NODE *subs) return symbol->alookup(symbol, subs); } -/* null_length --- default function for array length interface */ - -NODE ** -null_length(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED) -{ - static NODE *tmp; - tmp = symbol; - return & tmp; -} /* null_afunc --- default function for array interface */ diff --git a/awk.h b/awk.h index 6f0f5163..cb98491b 100644 --- a/awk.h +++ b/awk.h @@ -540,29 +540,26 @@ typedef struct exp_node { #define xarray sub.nodep.rn #define parent_array sub.nodep.x.extra -#define ainit array_funcs[0] #define ainit_ind 0 -#define atypeof array_funcs[1] +#define ainit array_funcs[ainit_ind] #define atypeof_ind 1 -#define alength array_funcs[2] -#define alength_ind 2 -#define alookup array_funcs[3] -#define alookup_ind 3 -#define aexists array_funcs[4] -#define aexists_ind 4 -#define aclear array_funcs[5] -#define aclear_ind 5 -#define aremove array_funcs[6] -#define aremove_ind 6 -#define alist array_funcs[7] -#define alist_ind 7 -#define acopy array_funcs[8] -#define acopy_ind 8 -#define adump array_funcs[9] -#define adump_ind 9 -#define astore array_funcs[10] -#define astore_ind 10 -#define NUM_AFUNCS 11 /* # of entries in array_funcs */ +#define atypeof array_funcs[atypeof_ind] +#define alookup_ind 2 +#define alookup array_funcs[alookup_ind] +#define aexists_ind 3 +#define aexists array_funcs[aexists_ind] +#define aclear_ind 4 +#define aclear array_funcs[aclear_ind] +#define aremove_ind 5 +#define aremove array_funcs[aremove_ind] +#define alist_ind 6 +#define alist array_funcs[alist_ind] +#define acopy_ind 7 +#define acopy array_funcs[acopy_ind] +#define adump_ind 8 +#define adump array_funcs[adump_ind] +#define astore_ind 9 +#define astore array_funcs[astore_ind] /* Node_array_ref: */ #define orig_array lnode @@ -1343,7 +1340,7 @@ DEREF(NODE *r) extern jmp_buf fatal_tag; extern int fatal_tag_valid; -#define assoc_length(a) ((*((a)->alength(a, NULL)))->table_size) +#define assoc_length(a) ((a)->table_size) #define assoc_empty(a) (assoc_length(a) == 0) #define assoc_lookup(a, s) ((a)->alookup(a, s)) @@ -1376,7 +1373,6 @@ extern const char *make_aname(const NODE *symbol); extern const char *array_vname(const NODE *symbol); extern void array_init(void); extern int register_array_func(afunc_t *afunc); -extern NODE **null_length(NODE *symbol, NODE *subs); extern NODE **null_afunc(NODE *symbol, NODE *subs); extern void set_SUBSEP(void); extern NODE *concat_exp(int nargs, bool do_subsep); diff --git a/cint_array.c b/cint_array.c index 05b94400..7db45fd2 100644 --- a/cint_array.c +++ b/cint_array.c @@ -62,7 +62,6 @@ static void cint_print(NODE *symbol); afunc_t cint_array_func[] = { cint_array_init, is_uinteger, - null_length, cint_lookup, cint_exists, cint_clear, diff --git a/gawkapi.c b/gawkapi.c index 7b1445c4..037ca430 100644 --- a/gawkapi.c +++ b/gawkapi.c @@ -1179,7 +1179,7 @@ api_flatten_array_typed(awk_ext_id_t id, if ( array == NULL || array->type != Node_var_array - || array->table_size == 0 + || assoc_empty(array) || data == NULL) return awk_false; diff --git a/int_array.c b/int_array.c index 069e027d..9f705176 100644 --- a/int_array.c +++ b/int_array.c @@ -49,7 +49,6 @@ static void grow_int_table(NODE *symbol); afunc_t int_array_func[] = { int_array_init, is_integer, - null_length, int_lookup, int_exists, int_clear, diff --git a/str_array.c b/str_array.c index bc6584d2..4972a92b 100644 --- a/str_array.c +++ b/str_array.c @@ -59,7 +59,6 @@ static NODE **str_dump(NODE *symbol, NODE *ndump); afunc_t str_array_func[] = { str_array_init, (afunc_t) 0, - null_length, str_lookup, str_exists, str_clear, @@ -78,7 +77,6 @@ static NODE **env_clear(NODE *symbol, NODE *subs); afunc_t env_array_func[] = { str_array_init, (afunc_t) 0, - null_length, str_lookup, str_exists, env_clear, diff --git a/symbol.c b/symbol.c index 797b5ec4..9f8af3a0 100644 --- a/symbol.c +++ b/symbol.c @@ -106,7 +106,7 @@ lookup(const char *name) n = NULL; for (i = 0; tables[i] != NULL; i++) { - if (tables[i]->table_size == 0) + if (assoc_empty(tables[i])) continue; if ((do_posix || do_traditional) && tables[i] == global_table) @@ -644,7 +644,7 @@ check_param_names(void) bool result = true; NODE n; - if (func_table->table_size == 0) + if (assoc_empty(func_table)) return result; max = func_table->table_size * 2; -- cgit v1.2.3