ruby-changes:24594
From: nobu <ko1@a...>
Date: Tue, 7 Aug 2012 00:24:57 +0900 (JST)
Subject: [ruby-changes:24594] nobu:r36645 (trunk): variable.c: split CVAR_LOOKUP
nobu 2012-08-07 00:24:01 +0900 (Tue, 07 Aug 2012) New Revision: 36645 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36645 Log: variable.c: split CVAR_LOOKUP * variable.c (CVAR_LOOKUP): split into helper functions. Modified files: trunk/ChangeLog trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 36644) +++ ChangeLog (revision 36645) @@ -1,3 +1,7 @@ +Tue Aug 7 00:23:58 2012 Nobuyoshi Nakada <nobu@r...> + + * variable.c (CVAR_LOOKUP): split into helper functions. + Mon Aug 6 19:15:11 2012 Masaki Suketa <masaki.suketa@n...> * test/win32ole/test_win32ole_variant.rb: setting WIN32OLE.locale Index: variable.c =================================================================== --- variable.c (revision 36644) +++ variable.c (revision 36645) @@ -2249,28 +2249,35 @@ return c; } +static int +cvar_lookup_at(VALUE klass, ID id, st_data_t *v) +{ + if (!RCLASS_IV_TBL(klass)) return 0; + return st_lookup(RCLASS_IV_TBL(klass), (st_data_t)id, v); +} + +static VALUE +cvar_front_klass(VALUE klass) +{ + if (FL_TEST(klass, FL_SINGLETON)) { + VALUE obj = rb_iv_get(klass, "__attached__"); + if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) { + return obj; + } + } + return RCLASS_SUPER(klass); +} + +#define CVAR_FOREACH_ANCESTORS(klass, v, r) \ + for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \ + if (cvar_lookup_at(klass, id, (v))) { \ + r; \ + } \ + } + #define CVAR_LOOKUP(v,r) do {\ - if (RCLASS_IV_TBL(klass) && st_lookup(RCLASS_IV_TBL(klass),(st_data_t)id,(v))) {\ - r;\ - }\ - if (FL_TEST(klass, FL_SINGLETON) ) {\ - VALUE obj = rb_iv_get(klass, "__attached__");\ - if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {\ - klass = obj;\ - }\ - else {\ - klass = RCLASS_SUPER(klass);\ - }\ - }\ - else {\ - klass = RCLASS_SUPER(klass);\ - }\ - while (klass) {\ - if (RCLASS_IV_TBL(klass) && st_lookup(RCLASS_IV_TBL(klass),(st_data_t)id,(v))) {\ - r;\ - }\ - klass = RCLASS_SUPER(klass);\ - }\ + if (cvar_lookup_at(klass, id, (v))) {r;}\ + CVAR_FOREACH_ANCESTORS(klass, v, r);\ } while(0) void -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/