[macruby-changes] [2386] MacRuby/trunk/object.c
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 25 20:11:19 PDT 2009
Revision: 2386
http://trac.macosforge.org/projects/ruby/changeset/2386
Author: lsansonetti at apple.com
Date: 2009-08-25 20:11:19 -0700 (Tue, 25 Aug 2009)
Log Message:
-----------
optimized #kind_of? to only lookup included modules if necessary
Modified Paths:
--------------
MacRuby/trunk/object.c
Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c 2009-08-26 03:10:38 UTC (rev 2385)
+++ MacRuby/trunk/object.c 2009-08-26 03:11:19 UTC (rev 2386)
@@ -554,29 +554,37 @@
rb_obj_is_kind_of(VALUE obj, VALUE c)
{
VALUE cl = CLASS_OF(obj);
+ bool is_module = false;
switch (TYPE(c)) {
case T_MODULE:
+ is_module = true;
+ // fall through
case T_CLASS:
case T_ICLASS:
- break;
+ break;
default:
- rb_raise(rb_eTypeError, "class or module required");
+ rb_raise(rb_eTypeError, "class or module required");
}
+ if (RCLASS_META(cl)) {
+ is_module = true;
+ }
+
while (cl) {
- VALUE ary;
if (cl == c) {
return Qtrue;
}
- ary = rb_attr_get(cl, idIncludedModules);
- if (ary != Qnil) {
- int i, count;
- for (i = 0, count = RARRAY_LEN(ary); i < count; i++) {
- VALUE imod = RARRAY_AT(ary, i);
- if (imod == c) {
- return Qtrue;
+ if (is_module) {
+ VALUE ary = rb_attr_get(cl, idIncludedModules);
+ if (ary != Qnil) {
+ int i, count;
+ for (i = 0, count = RARRAY_LEN(ary); i < count; i++) {
+ VALUE imod = RARRAY_AT(ary, i);
+ if (imod == c) {
+ return Qtrue;
+ }
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090825/29576c9d/attachment.html>
More information about the macruby-changes
mailing list