summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-06-05 07:19:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-06-05 07:19:39 +0000
commitd6c60dbf6d42f411a31a1c2e768a5a986a270a8c (patch)
treee8848119511789017b7c0dbf29f8cd37376737e5 /variable.c
parent21524a3fc00d0e894d0ca0b8fcb7d9c7413c5917 (diff)
* variable.c (rb_mod_const_at): use hash table as internal
data. [new] * variable.c (rb_mod_const_of): ditto. * variable.c (rb_const_list): new function to convert internal data (hash table) to array of strings. * eval.c (rb_mod_s_constants): data handling scheme has changed. * eval.c (rb_add_method): should not call rb_secure(), for last_func may not be set. * io.c (rb_io_ctl): ioctl should accept any integer within C long range. * marshal.c (r_object): wrong type check for modules. * marshal.c (w_object): should not dump anonymous classes/modules. * io.c (rb_open_file): use rb_file_sysopen_internal() if the 3rd argument (permission flags) is given. [new, should be backported?] * io.c (rb_io_mode_binmode): mode string (e.g. "r+") to flags to open(2). * eval.c (rb_eval): NODE_REXPAND expand an array of 1 element as the element itself. [new, should be backported?] * parse.y (ret_args): should treat "*[a]" in rhs expression as "a", not "[a]". * regex.c (re_compile_pattern): should push option modifier at the right place. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c90
1 files changed, 58 insertions, 32 deletions
diff --git a/variable.c b/variable.c
index fe0272d21e..f0ae3bfe22 100644
--- a/variable.c
+++ b/variable.c
@@ -1092,21 +1092,6 @@ rb_const_get(klass, id)
return Qnil; /* not reached */
}
-static int
-sv_i(key, value, ary)
- ID key;
- VALUE value;
- VALUE ary;
-{
- if (rb_is_const_id(key)) {
- VALUE kval = rb_str_new2(rb_id2name(key));
- if (!rb_ary_includes(ary, kval)) {
- rb_ary_push(ary, kval);
- }
- }
- return ST_CONTINUE;
-}
-
VALUE
rb_mod_remove_const(mod, name)
VALUE mod, name;
@@ -1134,44 +1119,85 @@ rb_mod_remove_const(mod, name)
}
static int
-autoload_i(key, name, ary)
+sv_i(key, value, tbl)
+ ID key;
+ VALUE value;
+ st_table *tbl;
+{
+ if (rb_is_const_id(key)) {
+ if (!st_lookup(tbl, key, 0)) {
+ st_insert(tbl, key, key);
+ }
+ }
+ return ST_CONTINUE;
+}
+
+static int
+autoload_i(key, name, tbl)
ID key;
const char *name;
- VALUE ary;
+ st_table *tbl;
{
- VALUE kval = rb_str_new2(rb_id2name(key));
- if (!rb_ary_includes(ary, kval)) {
- rb_ary_push(ary, kval);
+ if (!st_lookup(tbl, key, 0)) {
+ st_insert(tbl, key, key);
}
return ST_CONTINUE;
}
-VALUE
-rb_mod_const_at(mod, ary)
- VALUE mod, ary;
+void*
+rb_mod_const_at(mod, data)
+ VALUE mod;
+ void *data;
{
+ st_table *tbl = data;
+ if (!tbl) {
+ tbl = st_init_numtable();
+ }
if (RCLASS(mod)->iv_tbl) {
- st_foreach(RCLASS(mod)->iv_tbl, sv_i, ary);
+ st_foreach(RCLASS(mod)->iv_tbl, sv_i, tbl);
}
if ((VALUE)mod == rb_cObject) {
- st_foreach(rb_class_tbl, sv_i, ary);
+ st_foreach(rb_class_tbl, sv_i, tbl);
if (autoload_tbl) {
- st_foreach(autoload_tbl, autoload_i, ary);
+ st_foreach(autoload_tbl, autoload_i, tbl);
}
}
- return ary;
+ return tbl;
}
-VALUE
-rb_mod_const_of(mod, ary)
+void*
+rb_mod_const_of(mod, data)
VALUE mod;
- VALUE ary;
+ void *data;
{
for (;;) {
- rb_mod_const_at(mod, ary);
+ data = rb_mod_const_at(mod, data);
mod = RCLASS(mod)->super;
if (!mod) break;
}
+ return data;
+}
+
+static int
+list_i(key, value, ary)
+ ID key, value;
+ VALUE ary;
+{
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
+ return ST_CONTINUE;
+}
+
+VALUE
+rb_const_list(data)
+ void *data;
+{
+ st_table *tbl = data;
+ VALUE ary;
+
+ if (!tbl) return rb_ary_new2(0);
+ ary = rb_ary_new2(tbl->num_entries);
+ st_foreach(tbl, list_i, ary);
+
return ary;
}
@@ -1179,7 +1205,7 @@ VALUE
rb_mod_constants(mod)
VALUE mod;
{
- return rb_mod_const_of(mod, rb_ary_new());
+ return rb_const_list(rb_mod_const_of(mod, 0));
}
int