From 3443e43b625f4ba1821a101df9cdfd88347fbe6c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 16 Jun 2023 22:14:50 +0900 Subject: [PATCH] Remove `st_functions_t` --- parser_st.c | 33 ++++++++++++++++----------------- parser_st.h | 21 ++++++++------------- ruby_parser.c | 2 -- rubyparser.h | 3 --- universal_parser.c | 5 ++--- 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/parser_st.c b/parser_st.c index 9f600c5d1f..7dbeaaf28a 100644 --- a/parser_st.c +++ b/parser_st.c @@ -618,7 +618,7 @@ stat_col(void) entries. The real number of entries which the table can hold is the nearest power of two for SIZE. */ st_table * -st_init_table_with_size(const struct st_hash_type *type, st_functions_t *functions, st_index_t size) +st_init_table_with_size(const struct st_hash_type *type, st_index_t size) { st_table *tab; int n; @@ -642,7 +642,6 @@ st_init_table_with_size(const struct st_hash_type *type, st_functions_t *functio return NULL; #endif tab = (st_table *) malloc(sizeof (st_table)); - tab->functions = functions; #ifndef RUBY if (tab == NULL) return NULL; @@ -684,55 +683,55 @@ st_table_size(const struct st_table *tbl) /* Create and return table with TYPE which can hold a minimal number of entries (see comments for get_power2). */ st_table * -st_init_table(const struct st_hash_type *type, st_functions_t *functions) +st_init_table(const struct st_hash_type *type) { - return st_init_table_with_size(type, functions, 0); + return st_init_table_with_size(type, 0); } /* Create and return table which can hold a minimal number of numbers. */ st_table * -st_init_numtable(st_functions_t *functions) +st_init_numtable(void) { - return st_init_table(&type_numhash, functions); + return st_init_table(&type_numhash); } /* Create and return table which can hold SIZE numbers. */ st_table * -st_init_numtable_with_size(st_functions_t *functions, st_index_t size) +st_init_numtable_with_size(st_index_t size) { - return st_init_table_with_size(&type_numhash, functions, size); + return st_init_table_with_size(&type_numhash, size); } /* Create and return table which can hold a minimal number of strings. */ st_table * -st_init_strtable(st_functions_t *functions) +st_init_strtable(void) { - return st_init_table(&type_strhash, functions); + return st_init_table(&type_strhash); } /* Create and return table which can hold SIZE strings. */ st_table * -st_init_strtable_with_size(st_functions_t *functions, st_index_t size) +st_init_strtable_with_size(st_index_t size) { - return st_init_table_with_size(&type_strhash, functions, size); + return st_init_table_with_size(&type_strhash, size); } /* Create and return table which can hold a minimal number of strings whose character case is ignored. */ st_table * -st_init_strcasetable(st_functions_t *functions) +st_init_strcasetable(void) { - return st_init_table(&type_strcasehash, functions); + return st_init_table(&type_strcasehash); } /* Create and return table which can hold SIZE strings whose character case is ignored. */ st_table * -st_init_strcasetable_with_size(st_functions_t *functions, st_index_t size) +st_init_strcasetable_with_size(st_index_t size) { - return st_init_table_with_size(&type_strcasehash, functions, size); + return st_init_table_with_size(&type_strcasehash, size); } /* Make table TAB empty. */ @@ -837,7 +836,7 @@ rebuild_table(st_table *tab) /* This allocation could trigger GC and compaction. If tab is the * gen_iv_tbl, then tab could have changed in size due to objects being * freed and/or moved. Do not store attributes of tab before this line. */ - new_tab = st_init_table_with_size(tab->type, tab->functions, + new_tab = st_init_table_with_size(tab->type, 2 * tab->num_entries - 1); new_entries = new_tab->entries; } diff --git a/parser_st.h b/parser_st.h index ee603fbceb..6f72220380 100644 --- a/parser_st.h +++ b/parser_st.h @@ -67,10 +67,6 @@ struct parser_st_hash_type { parser_st_index_t (*hash)(parser_st_data_t); /* parser_st_hash_func* */ }; -typedef struct st_functions { - void *(*nonempty_memcpy)(void *dest, const void *src, size_t t, size_t n); -} st_functions_t; - #define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT) #if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P) @@ -100,7 +96,6 @@ struct parser_st_table { parser_st_index_t entries_start, entries_bound; /* Array of size 2^entry_power. */ parser_st_table_entry *entries; - st_functions_t *functions; }; #define parser_st_is_member(table,key) rb_parser_st_lookup((table),(key),(parser_st_data_t *)0) @@ -108,14 +103,14 @@ struct parser_st_table { enum parser_st_retval {ST2_CONTINUE, ST2_STOP, ST2_DELETE, ST2_CHECK, ST2_REPLACE}; size_t rb_parser_st_table_size(const struct parser_st_table *tbl); -parser_st_table *rb_parser_st_init_table(const struct parser_st_hash_type *, st_functions_t *); -parser_st_table *rb_parser_st_init_table_with_size(const struct parser_st_hash_type *, st_functions_t *, parser_st_index_t); -parser_st_table *rb_parser_st_init_numtable(st_functions_t *); -parser_st_table *rb_parser_st_init_numtable_with_size(st_functions_t *, parser_st_index_t); -parser_st_table *rb_parser_st_init_strtable(st_functions_t *); -parser_st_table *rb_parser_st_init_strtable_with_size(st_functions_t *, parser_st_index_t); -parser_st_table *rb_parser_st_init_strcasetable(st_functions_t *); -parser_st_table *rb_parser_st_init_strcasetable_with_size(st_functions_t *, parser_st_index_t); +parser_st_table *rb_parser_st_init_table(const struct parser_st_hash_type *); +parser_st_table *rb_parser_st_init_table_with_size(const struct parser_st_hash_type *, parser_st_index_t); +parser_st_table *rb_parser_st_init_numtable(void); +parser_st_table *rb_parser_st_init_numtable_with_size(parser_st_index_t); +parser_st_table *rb_parser_st_init_strtable(void); +parser_st_table *rb_parser_st_init_strtable_with_size(parser_st_index_t); +parser_st_table *rb_parser_st_init_strcasetable(void); +parser_st_table *rb_parser_st_init_strcasetable_with_size(parser_st_index_t); int rb_parser_st_delete(parser_st_table *, parser_st_data_t *, parser_st_data_t *); /* returns 0:notfound 1:deleted */ int rb_parser_st_delete_safe(parser_st_table *, parser_st_data_t *, parser_st_data_t *, parser_st_data_t); int rb_parser_st_shift(parser_st_table *, parser_st_data_t *, parser_st_data_t *); /* returns 0:notfound 1:deleted */ diff --git a/ruby_parser.c b/ruby_parser.c index 42c267fbdf..94c2c1f4ec 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -576,8 +576,6 @@ rb_parser_config_initialize(rb_parser_config_t *config) { config->counter = 0; - config->st_functions.nonempty_memcpy = nonempty_memcpy; - config->malloc = ruby_xmalloc; config->calloc = ruby_xcalloc; config->realloc = ruby_xrealloc; diff --git a/rubyparser.h b/rubyparser.h index 5fbc1de340..848002e64e 100644 --- a/rubyparser.h +++ b/rubyparser.h @@ -341,9 +341,6 @@ typedef struct rb_parser_config_struct { */ int counter; - /* For parser_st */ - st_functions_t st_functions; - /* Memory */ void *(*malloc)(size_t size); void *(*calloc)(size_t number, size_t size); diff --git a/universal_parser.c b/universal_parser.c index 9e4260f05d..8599c3b947 100644 --- a/universal_parser.c +++ b/universal_parser.c @@ -48,7 +48,7 @@ #define ST_CHECK ST2_CHECK #define ST_REPLACE ST2_REPLACE #undef st_init_numtable -#define st_init_numtable() rb_parser_st_init_numtable((&p->config->st_functions)) +#define st_init_numtable rb_parser_st_init_numtable #undef st_free_table #define st_free_table rb_parser_st_free_table #undef st_init_table_with_size @@ -393,8 +393,7 @@ struct rb_imemo_tmpbuf_struct { #define rb_node_case_when_optimizable_literal p->config->node_case_when_optimizable_literal #undef st_init_table_with_size -#define st_init_table_with_size(type, size) \ - rb_parser_st_init_table_with_size(type, &p->config->st_functions, size) +#define st_init_table_with_size rb_parser_st_init_table_with_size #define rb_ast_new() \ rb_ast_new(p->config)