[macruby-changes] [5203] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 27 22:03:18 PST 2011
Revision: 5203
http://trac.macosforge.org/projects/ruby/changeset/5203
Author: lsansonetti at apple.com
Date: 2011-01-27 22:03:17 -0800 (Thu, 27 Jan 2011)
Log Message:
-----------
refactor duplicated code
Modified Paths:
--------------
MacRuby/trunk/class.c
MacRuby/trunk/compiler.cpp
MacRuby/trunk/enumerator.c
MacRuby/trunk/vm.cpp
MacRuby/trunk/vm_eval.c
Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c 2011-01-28 05:41:23 UTC (rev 5202)
+++ MacRuby/trunk/class.c 2011-01-28 06:03:17 UTC (rev 5203)
@@ -979,17 +979,6 @@
return ary;
}
-static SEL
-name_to_sel(const char *name, const int arity)
-{
- if (arity > 0) {
- char buf[100];
- snprintf(buf, sizeof buf, "%s:", name);
- return sel_registerName(buf);
- }
- return sel_registerName(name);
-}
-
static void
rb_objc_add_method(VALUE klass, const char *name, void *imp, const int arity,
const int noex, bool direct)
@@ -1001,7 +990,7 @@
NODE *body = rb_vm_cfunc_node_from_imp((Class)klass, arity, (IMP)imp, noex);
GC_RETAIN(body);
- rb_vm_define_method((Class)klass, name_to_sel(name, arity), (IMP)imp,
+ rb_vm_define_method((Class)klass, rb_vm_name_to_sel(name, arity), (IMP)imp,
body, direct);
}
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2011-01-28 05:41:23 UTC (rev 5202)
+++ MacRuby/trunk/compiler.cpp 2011-01-28 06:03:17 UTC (rev 5203)
@@ -340,20 +340,12 @@
SEL
RoxorCompiler::mid_to_sel(ID mid, int arity)
{
- SEL sel;
- const char *mid_str = rb_id2name(mid);
- char buf[100];
- if (mid_str[strlen(mid_str) - 1] != ':' && arity > 0) {
- snprintf(buf, sizeof buf, "%s:", mid_str);
+ SEL sel = rb_vm_id_to_sel(mid, arity);
+ if (rb_objc_ignored_sel(sel)) {
+ char buf[100];
+ snprintf(buf, sizeof buf, "__hidden__%s", rb_id2name(mid));
sel = sel_registerName(buf);
}
- else {
- sel = sel_registerName(mid_str);
- if (rb_objc_ignored_sel(sel)) {
- snprintf(buf, sizeof buf, "__hidden__%s", mid_str);
- sel = sel_registerName(buf);
- }
- }
return sel;
}
Modified: MacRuby/trunk/enumerator.c
===================================================================
--- MacRuby/trunk/enumerator.c 2011-01-28 05:41:23 UTC (rev 5202)
+++ MacRuby/trunk/enumerator.c 2011-01-28 06:03:17 UTC (rev 5203)
@@ -7,6 +7,8 @@
#include "macruby_internal.h"
#include "id.h"
+#include "ruby/node.h"
+#include "vm.h"
/*
* Document-class: Enumerable::Enumerator
@@ -77,15 +79,7 @@
}
ID meth_id = rb_to_id(meth);
- SEL enum_sel;
- if (argc > 0) {
- char buf[100];
- snprintf(buf, sizeof buf, "%s:", rb_id2name(meth_id));
- enum_sel = sel_registerName(buf);
- }
- else {
- enum_sel = sel_registerName(rb_id2name(meth_id));
- }
+ SEL enum_sel = rb_vm_id_to_sel(meth_id, argc);
return rb_enumeratorize(obj, enum_sel, argc, argv);
}
@@ -251,15 +245,7 @@
--argc;
}
ID meth_id = rb_to_id(meth);
- SEL meth_sel;
- if (argc == 0) {
- meth_sel = sel_registerName(rb_id2name(meth_id));
- }
- else {
- char buf[100];
- snprintf(buf, sizeof buf, "%s:", rb_id2name(meth_id));
- meth_sel = sel_registerName(buf);
- }
+ SEL meth_sel = rb_vm_id_to_sel(meth_id, argc);
return enumerator_init(obj, recv, meth_sel, argc, argv);
}
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2011-01-28 05:41:23 UTC (rev 5202)
+++ MacRuby/trunk/vm.cpp 2011-01-28 06:03:17 UTC (rev 5203)
@@ -1479,19 +1479,9 @@
if (UNAVAILABLE_IMP(imp)) {
return;
}
- const char *types = method_getTypeEncoding(method);
- const char *name_str = rb_id2name(name);
- SEL sel;
- if (noargs) {
- sel = sel_registerName(name_str);
- }
- else {
- char tmp[100];
- snprintf(tmp, sizeof tmp, "%s:", name_str);
- sel = sel_registerName(tmp);
- }
-
+ const char *types = method_getTypeEncoding(method);
+ SEL sel = rb_vm_id_to_sel(name, noargs ? 0 : 1);
rb_vm_method_node_t *node = GET_CORE()->method_node_get(method);
if (node != NULL) {
GET_CORE()->add_method(klass, sel, imp, node->ruby_imp,
Modified: MacRuby/trunk/vm_eval.c
===================================================================
--- MacRuby/trunk/vm_eval.c 2011-01-28 05:41:23 UTC (rev 5202)
+++ MacRuby/trunk/vm_eval.c 2011-01-28 06:03:17 UTC (rev 5203)
@@ -26,17 +26,8 @@
sel = selAlloc;
}
else {
- const char *midstr = rb_id2name(mid);
- if (argc > 0 && midstr[strlen(midstr) - 1] != ':') {
- char buf[100];
- snprintf(buf, sizeof buf, "%s:", midstr);
- sel = sel_registerName(buf);
- }
- else {
- sel = sel_registerName(midstr);
- }
+ sel = rb_vm_id_to_sel(mid, argc);
}
-
rb_vm_block_t *block = pass_current_block ? rb_vm_current_block() : NULL;
return rb_vm_call2(block, recv, CLASS_OF(recv), sel, argc, argv);
}
@@ -280,15 +271,7 @@
rb_block_call(VALUE obj, ID mid, int argc, VALUE *argv,
VALUE (*bl_proc) (ANYARGS), VALUE data2)
{
- SEL sel;
- if (argc == 0) {
- sel = sel_registerName(rb_id2name(mid));
- }
- else {
- char buf[100];
- snprintf(buf, sizeof buf, "%s:", rb_id2name(mid));
- sel = sel_registerName(buf);
- }
+ SEL sel = rb_vm_id_to_sel(mid, argc);
return rb_objc_block_call(obj, sel, argc, argv, bl_proc, data2);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110127/5e677f87/attachment-0001.html>
More information about the macruby-changes
mailing list