From c5c20752a8a471c16f8d410d9be00dd22fd6ceed Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 25 Sep 2015 13:14:16 +0000 Subject: marshal.c: reduce arity checks * marshal.c (rb_marshal_dump_limited): get rid of redundant arity check to dump object with limited nest level. * marshal.c (rb_marshal_load_with_proc): get rid of redundant arity check to load object with hook proc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- marshal.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'marshal.c') diff --git a/marshal.c b/marshal.c index 2a0b8c0d1a..752f0531b6 100644 --- a/marshal.c +++ b/marshal.c @@ -109,6 +109,8 @@ typedef struct { static st_table *compat_allocator_tbl; static VALUE compat_allocator_tbl_wrapper; +static VALUE rb_marshal_dump_limited(VALUE obj, VALUE port, int limit); +static VALUE rb_marshal_load_with_proc(VALUE port, VALUE proc); static int mark_marshal_compat_i(st_data_t key, st_data_t value) @@ -991,8 +993,6 @@ marshal_dump(int argc, VALUE *argv) { VALUE obj, port, a1, a2; int limit = -1; - struct dump_arg *arg; - VALUE wrapper; /* used to avoid memory leak in case of exception */ port = Qnil; rb_scan_args(argc, argv, "12", &obj, &a1, &a2); @@ -1006,6 +1006,15 @@ marshal_dump(int argc, VALUE *argv) else if (NIL_P(a1)) io_needed(); else port = a1; } + return rb_marshal_dump_limited(obj, port, limit); +} + +VALUE +rb_marshal_dump_limited(VALUE obj, VALUE port, int limit) +{ + struct dump_arg *arg; + VALUE wrapper; /* used to avoid memory leak in case of exception */ + wrapper = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg); arg->dest = 0; arg->symbols = st_init_numtable(); @@ -2005,12 +2014,21 @@ static VALUE marshal_load(int argc, VALUE *argv) { VALUE port, proc; + + rb_check_arity(argc, 1, 2); + port = argv[0]; + proc = argc > 1 ? argv[1] : Qnil; + return rb_marshal_load_with_proc(port, proc); +} + +VALUE +rb_marshal_load_with_proc(VALUE port, VALUE proc) +{ int major, minor, infection = 0; VALUE v; VALUE wrapper; /* used to avoid memory leak in case of exception */ struct load_arg *arg; - rb_scan_args(argc, argv, "11", &port, &proc); v = rb_check_string_type(port); if (!NIL_P(v)) { infection = (int)FL_TEST(port, MARSHAL_INFECTION); /* original taintedness */ @@ -2212,17 +2230,11 @@ Init_marshal(void) VALUE rb_marshal_dump(VALUE obj, VALUE port) { - int argc = 1; - VALUE argv[2]; - - argv[0] = obj; - argv[1] = port; - if (!NIL_P(port)) argc = 2; - return marshal_dump(argc, argv); + return rb_marshal_dump_limited(obj, port, -1); } VALUE rb_marshal_load(VALUE port) { - return marshal_load(1, &port); + return rb_marshal_load_with_proc(port, Qnil); } -- cgit v1.2.3