[前][次][番号順一覧][スレッド一覧]

ruby-changes:5365

From: ko1 <ko1@a...>
Date: Fri, 6 Jun 2008 23:48:22 +0900 (JST)
Subject: [ruby-changes:5365] Ruby:r16868 (trunk): * vm_insnhelper.c (vm_callee_setup_arg): check simple flag before

ko1	2008-06-06 23:48:07 +0900 (Fri, 06 Jun 2008)

  New Revision: 16868

  Modified files:
    trunk/ChangeLog
    trunk/vm_insnhelper.c

  Log:
    * vm_insnhelper.c (vm_callee_setup_arg): check simple flag before
      calling setup_arg function().  this change reduce function call.
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16868&r2=16867&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm_insnhelper.c?r1=16868&r2=16867&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16867)
+++ ChangeLog	(revision 16868)
@@ -1,3 +1,8 @@
+Fri Jun  6 23:46:19 2008  Koichi Sasada  <ko1@a...>
+
+	* vm_insnhelper.c (vm_callee_setup_arg): check simple flag before
+	  calling setup_arg function().  this change reduce function call.
+
 Fri Jun  6 21:51:46 2008  NAKAMURA Usaku  <usa@r...>
 
 	* win32/Makefile.sub (COMMON_HEADERS): include ws2tcpip.h.
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 16867)
+++ vm_insnhelper.c	(revision 16868)
@@ -98,109 +98,111 @@
 
 /* method dispatch */
 
+#define VM_CALLEE_SETUP_ARG(ret, th, iseq, orig_argc, orig_argv, block) \
+    if (LIKELY(iseq->arg_simple & 0x01)) { \
+	/* simple check */ \
+	if (orig_argc != iseq->argc) { \
+	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", orig_argc, iseq->argc); \
+	} \
+	ret = 0; \
+    } \
+    else { \
+	ret = vm_callee_setup_arg_complex(th, iseq, orig_argc, orig_argv, block); \
+    }
+
 static inline int
-vm_callee_setup_arg(rb_thread_t *th, const rb_iseq_t * iseq,
-		    int orig_argc, VALUE * orig_argv, const rb_block_t **block)
+vm_callee_setup_arg_complex(rb_thread_t *th, const rb_iseq_t * iseq,
+			    int orig_argc, VALUE * orig_argv,
+			    const rb_block_t **block)
 {
     const int m = iseq->argc;
+    int argc = orig_argc;
+    VALUE *argv = orig_argv;
+    int opt_pc = 0;
 
-    if (LIKELY(iseq->arg_simple & 0x01)) {
-	/* simple check */
-	if (orig_argc != m) {
-	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
-		     orig_argc, m);
-	}
-	return 0;
+    th->mark_stack_len = argc + iseq->arg_size;
+
+    /* mandatory */
+    if (argc < (m + iseq->arg_post_len)) { /* check with post arg */
+	rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+		 argc, m + iseq->arg_post_len);
     }
-    else {
-	int argc = orig_argc;
-	VALUE *argv = orig_argv;
-	int opt_pc = 0;
 
-	th->mark_stack_len = argc + iseq->arg_size;
+    argv += m;
+    argc -= m;
 
-	/* mandatory */
-	if (argc < (m + iseq->arg_post_len)) { /* check with post arg */
-	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
-		     argc, m + iseq->arg_post_len);
+    /* post arguments */
+    if (iseq->arg_post_len) {
+	if (!(orig_argc < iseq->arg_post_start)) {
+	    VALUE *new_argv = ALLOCA_N(VALUE, argc);
+	    MEMCPY(new_argv, argv, VALUE, argc);
+	    argv = new_argv;
 	}
 
-	argv += m;
-	argc -= m;
+	MEMCPY(&orig_argv[iseq->arg_post_start], &argv[argc -= iseq->arg_post_len],
+	       VALUE, iseq->arg_post_len);
+    }
 
-	/* post arguments */
-	if (iseq->arg_post_len) {
-	    if (!(orig_argc < iseq->arg_post_start)) {
-		VALUE *new_argv = ALLOCA_N(VALUE, argc);
-		MEMCPY(new_argv, argv, VALUE, argc);
-		argv = new_argv;
-	    }
+    /* opt arguments */
+    if (iseq->arg_opts) {
+	const int opts = iseq->arg_opts - 1 /* no opt */;
 
-	    MEMCPY(&orig_argv[iseq->arg_post_start], &argv[argc -= iseq->arg_post_len],
-		   VALUE, iseq->arg_post_len);
+	if (iseq->arg_rest == -1 && argc > opts) {
+	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+		     orig_argc, m + opts + iseq->arg_post_len);
 	}
 
-	/* opt arguments */
-	if (iseq->arg_opts) {
-	    const int opts = iseq->arg_opts - 1 /* no opt */;
-
-	    if (iseq->arg_rest == -1 && argc > opts) {
-		rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
-			 orig_argc, m + opts + iseq->arg_post_len);
+	if (argc > opts) {
+	    argc -= opts;
+	    argv += opts;
+	    opt_pc = iseq->arg_opt_table[opts]; /* no opt */
+	}
+	else {
+	    int i;
+	    for (i = argc; i<opts; i++) {
+		orig_argv[i + m] = Qnil;
 	    }
-
-	    if (argc > opts) {
-		argc -= opts;
-		argv += opts;
-		opt_pc = iseq->arg_opt_table[opts]; /* no opt */
-	    }
-	    else {
-		int i;
-		for (i = argc; i<opts; i++) {
-		    orig_argv[i + m] = Qnil;
-		}
-		opt_pc = iseq->arg_opt_table[argc];
-		argc = 0;
-	    }
-	}
-
-	/* rest arguments */
-	if (iseq->arg_rest != -1) {
-	    orig_argv[iseq->arg_rest] = rb_ary_new4(argc, argv);
+	    opt_pc = iseq->arg_opt_table[argc];
 	    argc = 0;
 	}
+    }
 
-	/* block arguments */
-	if (block && iseq->arg_block != -1) {
-	    VALUE blockval = Qnil;
-	    const rb_block_t *blockptr = *block;
+    /* rest arguments */
+    if (iseq->arg_rest != -1) {
+	orig_argv[iseq->arg_rest] = rb_ary_new4(argc, argv);
+	argc = 0;
+    }
 
-	    if (argc != 0) {
-		rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
-			 orig_argc, m + iseq->arg_post_len);
-	    }
+    /* block arguments */
+    if (block && iseq->arg_block != -1) {
+	VALUE blockval = Qnil;
+	const rb_block_t *blockptr = *block;
 
-	    if (blockptr) {
-		/* make Proc object */
-		if (blockptr->proc == 0) {
-		    rb_proc_t *proc;
+	if (argc != 0) {
+	    rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+		     orig_argc, m + iseq->arg_post_len);
+	}
 
-		    blockval = vm_make_proc(th, th->cfp, blockptr);
+	if (blockptr) {
+	    /* make Proc object */
+	    if (blockptr->proc == 0) {
+		rb_proc_t *proc;
 
-		    GetProcPtr(blockval, proc);
-		    *block = &proc->block;
-		}
-		else {
-		    blockval = blockptr->proc;
-		}
+		blockval = vm_make_proc(th, th->cfp, blockptr);
+
+		GetProcPtr(blockval, proc);
+		*block = &proc->block;
 	    }
-
-	    orig_argv[iseq->arg_block] = blockval; /* Proc or nil */
+	    else {
+		blockval = blockptr->proc;
+	    }
 	}
 
-	th->mark_stack_len = 0;
-	return opt_pc;
+	orig_argv[iseq->arg_block] = blockval; /* Proc or nil */
     }
+
+    th->mark_stack_len = 0;
+    return opt_pc;
 }
 
 static inline int
@@ -436,7 +438,7 @@
 
     /* TODO: eliminate it */
     GetISeqPtr(iseqval, iseq);
-    opt_pc = vm_callee_setup_arg(th, iseq, argc, rsp, &blockptr);
+    VM_CALLEE_SETUP_ARG(opt_pc, th, iseq, argc, rsp, &blockptr);
 
     /* stack overflow check */
     CHECK_STACK_OVERFLOW(cfp, iseq->stack_max);
@@ -694,7 +696,9 @@
 
     if (lambda) {
 	/* call as method */
-	return vm_callee_setup_arg(th, iseq, orig_argc, argv, &blockptr);
+	int opt_pc;
+	VM_CALLEE_SETUP_ARG(opt_pc, th, iseq, orig_argc, argv, &blockptr);
+	return opt_pc;
     }
     else {
 	int i;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]