diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-06 15:24:01 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-06 15:24:01 +0000 |
commit | 6f677a5e0042442a6c70a8bcb003f702f4222e58 (patch) | |
tree | 36ee1da275558f94f3ec11388b192571e2423449 | |
parent | 745de093dbe5d110e6cc7e5ab05e619f0f41b764 (diff) | |
download | ruby-6f677a5e0042442a6c70a8bcb003f702f4222e58.tar.gz |
variable.c: split CVAR_LOOKUP
* variable.c (CVAR_LOOKUP): split into helper functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | variable.c | 49 |
2 files changed, 32 insertions, 21 deletions
@@ -1,3 +1,7 @@ +Tue Aug 7 00:23:58 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * variable.c (CVAR_LOOKUP): split into helper functions. + Mon Aug 6 19:15:11 2012 Masaki Suketa <masaki.suketa@nifty.ne.jp> * test/win32ole/test_win32ole_variant.rb: setting WIN32OLE.locale diff --git a/variable.c b/variable.c index 8a8d462910..b9c473d208 100644 --- a/variable.c +++ b/variable.c @@ -2249,28 +2249,35 @@ original_module(VALUE c) 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 |