MRI: some minor optimizations

This commit is contained in:
cremno 2014-01-24 22:23:30 +01:00
parent cb39c2f345
commit f06769b434
6 changed files with 24 additions and 22 deletions

View File

@ -126,7 +126,7 @@ static void printP(int argc, VALUE *argv,
for (int i = 0; i < argc; ++i)
{
VALUE str = rb_funcall(argv[i], conv, 0);
VALUE str = rb_funcall2(argv[i], conv, 0, NULL);
rb_str_buf_append(dispString, str);
if (i < argc)
@ -210,12 +210,12 @@ static void runRMXPScripts()
return;
}
size_t scriptCount = RARRAY_LEN(scriptArray);
long scriptCount = RARRAY_LEN(scriptArray);
std::string decodeBuffer;
decodeBuffer.resize(0x1000);
for (size_t i = 0; i < scriptCount; ++i)
for (long i = 0; i < scriptCount; ++i)
{
VALUE script = rb_ary_entry(scriptArray, i);
@ -251,8 +251,7 @@ static void runRMXPScripts()
if (result != Z_OK)
{
static char buffer[256];
/* FIXME: '%zu' apparently gcc only? */
snprintf(buffer, sizeof(buffer), "Error decoding script %zu: '%s'",
snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'",
i, RSTRING_PTR(scriptName));
showMsg(buffer);
@ -274,8 +273,8 @@ static void runRMXPScripts()
/* Execute code */
rb_eval_string_protect(decData.c_str(), 0);
VALUE exc = rb_gv_get("$!");
if (rb_type(exc) != RUBY_T_NIL)
VALUE exc = rb_errinfo();
if (!NIL_P(exc))
break;
}
}
@ -296,13 +295,13 @@ static void mriBindingExecute()
else
runRMXPScripts();
VALUE exc = rb_gv_get("$!");
if (rb_type(exc) != RUBY_T_NIL && !rb_eql(rb_obj_class(exc), rb_eSystemExit))
VALUE exc = rb_errinfo();
if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
{
Debug() << "Had exception:" << rb_class2name(rb_obj_class(exc));
VALUE bt = rb_funcall(exc, rb_intern("backtrace"), 0);
VALUE bt = rb_funcall2(exc, rb_intern("backtrace"), 0, NULL);
rb_p(bt);
VALUE msg = rb_funcall(exc, rb_intern("message"), 0);
VALUE msg = rb_funcall2(exc, rb_intern("message"), 0, NULL);
if (RSTRING_LEN(msg) < 256)
showMsg(RSTRING_PTR(msg));
else

View File

@ -322,7 +322,7 @@ rb_check_argc(int actual, int expected)
Klass *k = getPrivateData<Klass>(self); \
VALUE propObj = *argv; \
PropKlass *prop; \
if (rb_type(propObj) == RUBY_T_NIL) \
if (NIL_P(propObj)) \
prop = 0; \
else \
prop = getPrivateDataCheck<PropKlass>(propObj, PropKlass##Type); \

View File

@ -23,6 +23,7 @@
#include "sharedstate.h"
#include "filesystem.h"
#include "util.h"
#include "ruby/encoding.h"
#include "ruby/intern.h"
@ -118,9 +119,9 @@ kernelLoadDataInt(const char *filename)
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
// FIXME need to catch exceptions here with begin rescue
VALUE result = rb_funcall(marsh, rb_intern("load"), 1, port);
VALUE result = rb_funcall2(marsh, rb_intern("load"), 1, &port);
rb_funcall(port, rb_intern("close"), 0);
rb_funcall2(port, rb_intern("close"), 0, NULL);
return result;
}
@ -144,13 +145,14 @@ RB_METHOD(kernelSaveData)
rb_get_args(argc, argv, "oS", &obj, &filename RB_ARG_END);
VALUE file = rb_funcall(rb_cFile, rb_intern("open"), 2, filename, rb_str_new_cstr("w"));
VALUE file = rb_file_open_str(filename, "wb");
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
rb_funcall(marsh, rb_intern("dump"), 2, obj, file);
VALUE v[] = { obj, file };
rb_funcall2(marsh, rb_intern("dump"), ARRAY_SIZE(v), v);
rb_funcall(file, rb_intern("close"), 0);
rb_io_close(file);
return Qnil;
}
@ -187,7 +189,8 @@ RB_METHOD(_marshalLoad)
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
return rb_funcall(marsh, rb_intern("_mkxp_load_alias"), 2, port, utf8Proc);
VALUE v[] = { port, utf8Proc };
return rb_funcall2(marsh, rb_intern("_mkxp_load_alias"), ARRAY_SIZE(v), v);
}
void

View File

@ -38,7 +38,7 @@ RB_METHOD(flashableFlash)
rb_get_args(argc, argv, "oi", &colorObj, &duration RB_ARG_END);
if (rb_type(colorObj) == RUBY_T_NIL)
if (NIL_P(rb_type(colorObj)))
{
f->flash(0, duration);
return Qnil;

View File

@ -74,7 +74,7 @@ RB_METHOD(tilemapInitialize)
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
if (rb_type(viewportObj) != RUBY_T_NIL)
if (!NIL_P(viewportObj))
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
/* Construct object */

View File

@ -54,7 +54,7 @@ RB_METHOD(viewportElementSetViewport)
rb_get_args(argc, argv, "o", &viewportObj RB_ARG_END);
if (rb_type(viewportObj) != RUBY_T_NIL)
if (!NIL_P(viewportObj))
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
GUARD_EXC( ve->setViewport(viewport); );
@ -76,7 +76,7 @@ viewportElementInitialize(int argc, VALUE *argv, VALUE self)
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
if (rb_type(viewportObj) != RUBY_T_NIL)
if (!NIL_P(viewportObj))
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
/* Construct object */