dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] variable.c (rb_global_tbl): convert to id_table
@ 2015-10-29 19:40 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-10-29 19:40 UTC (permalink / raw)
  To: spew

Trivial, as probably nothing depends on order of globals
---
 variable.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/variable.c b/variable.c
index 1d270e2..798481d 100644
--- a/variable.c
+++ b/variable.c
@@ -17,8 +17,9 @@
 #include "constant.h"
 #include "id.h"
 #include "ccan/list/list.h"
+#include "id_table.h"
 
-st_table *rb_global_tbl;
+struct rb_id_table *rb_global_tbl;
 static ID autoload, classpath, tmp_classpath, classid;
 
 static void check_before_mod_set(VALUE, ID, VALUE, const char *);
@@ -45,7 +46,7 @@ struct ivar_update {
 void
 Init_var_tables(void)
 {
-    rb_global_tbl = st_init_numtable();
+    rb_global_tbl = rb_id_table_create(0);
     generic_iv_tbl = st_init_numtable();
     autoload = rb_intern_const("__autoload__");
     /* __classpath__: fully qualified class path */
@@ -500,9 +501,9 @@ struct global_entry*
 rb_global_entry(ID id)
 {
     struct global_entry *entry;
-    st_data_t data;
+    VALUE data;
 
-    if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) {
+    if (!rb_id_table_lookup(rb_global_tbl, id, &data)) {
 	struct global_variable *var;
 	entry = ALLOC(struct global_entry);
 	var = ALLOC(struct global_variable);
@@ -516,7 +517,7 @@ rb_global_entry(ID id)
 
 	var->block_trace = 0;
 	var->trace = 0;
-	st_add_direct(rb_global_tbl, id, (st_data_t)entry);
+	rb_id_table_insert(rb_global_tbl, id, (VALUE)entry);
     }
     else {
 	entry = (struct global_entry *)data;
@@ -592,8 +593,8 @@ readonly_setter(VALUE val, ID id, void *data, struct global_variable *gvar)
     rb_name_error(id, "%"PRIsVALUE" is a read-only variable", QUOTE_ID(id));
 }
 
-static int
-mark_global_entry(st_data_t k, st_data_t v, st_data_t a)
+static enum rb_id_table_iterator_result
+mark_global_entry(VALUE v, void *ignored)
 {
     struct global_entry *entry = (struct global_entry *)v;
     struct trace_var *trace;
@@ -605,14 +606,14 @@ mark_global_entry(st_data_t k, st_data_t v, st_data_t a)
 	if (trace->data) rb_gc_mark_maybe(trace->data);
 	trace = trace->next;
     }
-    return ST_CONTINUE;
+    return ID_TABLE_CONTINUE;
 }
 
 void
 rb_gc_mark_global_tbl(void)
 {
     if (rb_global_tbl)
-        st_foreach_safe(rb_global_tbl, mark_global_entry, 0);
+        rb_id_table_foreach_values(rb_global_tbl, mark_global_entry, 0);
 }
 
 static ID
@@ -768,14 +769,14 @@ rb_f_untrace_var(int argc, const VALUE *argv)
     ID id;
     struct global_entry *entry;
     struct trace_var *trace;
-    st_data_t data;
+    VALUE data;
 
     rb_scan_args(argc, argv, "11", &var, &cmd);
     id = rb_check_id(&var);
     if (!id) {
 	rb_name_error_str(var, "undefined global variable %"PRIsVALUE"", QUOTE(var));
     }
-    if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) {
+    if (!rb_id_table_lookup(rb_global_tbl, id, &data)) {
 	rb_name_error(id, "undefined global variable %"PRIsVALUE"", QUOTE_ID(id));
     }
 
@@ -881,13 +882,12 @@ rb_gvar_defined(struct global_entry *entry)
     return Qtrue;
 }
 
-static int
-gvar_i(st_data_t k, st_data_t v, st_data_t a)
+static enum rb_id_table_iterator_result
+gvar_i(ID key, VALUE val, void *a)
 {
-    ID key = (ID)k;
     VALUE ary = (VALUE)a;
     rb_ary_push(ary, ID2SYM(key));
-    return ST_CONTINUE;
+    return ID_TABLE_CONTINUE;
 }
 
 /*
@@ -906,7 +906,7 @@ rb_f_global_variables(void)
     char buf[2];
     int i;
 
-    st_foreach_safe(rb_global_tbl, gvar_i, ary);
+    rb_id_table_foreach(rb_global_tbl, gvar_i, (void *)ary);
     buf[0] = '$';
     for (i = 1; i <= 9; ++i) {
 	buf[1] = (char)(i + '0');
@@ -919,13 +919,13 @@ void
 rb_alias_variable(ID name1, ID name2)
 {
     struct global_entry *entry1, *entry2;
-    st_data_t data1;
+    VALUE data1;
 
     entry2 = rb_global_entry(name2);
-    if (!st_lookup(rb_global_tbl, (st_data_t)name1, &data1)) {
+    if (!rb_id_table_lookup(rb_global_tbl, name1, &data1)) {
 	entry1 = ALLOC(struct global_entry);
 	entry1->id = name1;
-	st_add_direct(rb_global_tbl, name1, (st_data_t)entry1);
+	rb_id_table_insert(rb_global_tbl, name1, (VALUE)entry1);
     }
     else if ((entry1 = (struct global_entry *)data1)->var != entry2->var) {
 	struct global_variable *var = entry1->var;
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-10-29 19:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 19:40 [PATCH] variable.c (rb_global_tbl): convert to id_table Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).