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

ruby-changes:35482

From: normal <ko1@a...>
Date: Sat, 13 Sep 2014 06:34:27 +0900 (JST)
Subject: [ruby-changes:35482] normal:r47564 (trunk): proc/env DATA_PTR is never NULL

normal	2014-09-13 06:34:12 +0900 (Sat, 13 Sep 2014)

  New Revision: 47564

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47564

  Log:
    proc/env DATA_PTR is never NULL
    
    * proc.c (proc_free): remove, use RUBY_TYPED_DEFAULT_FREE
      (proc_mark, proc_memsize): remove needless branching
    
    * vm.c (env_free): remove, use RUBY_TYPED_DEFAULT_FREE
      (env_mark, env_memsize): remove needless branching
    
    This shows a tiny ~0.5% improvement in benchmark/bm_vm2_newlambda.rb
    but also removes a lot of code.

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/vm.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47563)
+++ ChangeLog	(revision 47564)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep 13 06:13:55 2014  Eric Wong  <e@8...>
+
+	* proc.c (proc_free): remove, use RUBY_TYPED_DEFAULT_FREE
+	  (proc_mark, proc_memsize): remove needless branching
+
+	* vm.c (env_free): remove, use RUBY_TYPED_DEFAULT_FREE
+	  (env_mark, env_memsize): remove needless branching
+
 Sat Sep 13 05:52:15 2014  Eric Wong  <e@8...>
 
 	* proc.c (rb_proc_alloc): inline and move to vm.c
Index: proc.c
===================================================================
--- proc.c	(revision 47563)
+++ proc.c	(revision 47564)
@@ -40,29 +40,16 @@ static int method_min_max_arity(VALUE, i https://github.com/ruby/ruby/blob/trunk/proc.c#L40
 #define IS_METHOD_PROC_NODE(node) (nd_type(node) == NODE_IFUNC && (node)->nd_cfnc == bmcall)
 
 static void
-proc_free(void *ptr)
-{
-    RUBY_FREE_ENTER("proc");
-    if (ptr) {
-	ruby_xfree(ptr);
-    }
-    RUBY_FREE_LEAVE("proc");
-}
-
-static void
 proc_mark(void *ptr)
 {
-    rb_proc_t *proc;
+    rb_proc_t *proc = ptr;
     RUBY_MARK_ENTER("proc");
-    if (ptr) {
-	proc = ptr;
-	RUBY_MARK_UNLESS_NULL(proc->envval);
-	RUBY_MARK_UNLESS_NULL(proc->blockprocval);
-	RUBY_MARK_UNLESS_NULL(proc->block.proc);
-	RUBY_MARK_UNLESS_NULL(proc->block.self);
-	if (proc->block.iseq && RUBY_VM_IFUNC_P(proc->block.iseq)) {
-	    RUBY_MARK_UNLESS_NULL((VALUE)(proc->block.iseq));
-	}
+    RUBY_MARK_UNLESS_NULL(proc->envval);
+    RUBY_MARK_UNLESS_NULL(proc->blockprocval);
+    RUBY_MARK_UNLESS_NULL(proc->block.proc);
+    RUBY_MARK_UNLESS_NULL(proc->block.self);
+    if (proc->block.iseq && RUBY_VM_IFUNC_P(proc->block.iseq)) {
+	RUBY_MARK_UNLESS_NULL((VALUE)(proc->block.iseq));
     }
     RUBY_MARK_LEAVE("proc");
 }
@@ -70,14 +57,14 @@ proc_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/proc.c#L57
 static size_t
 proc_memsize(const void *ptr)
 {
-    return ptr ? sizeof(rb_proc_t) : 0;
+    return sizeof(rb_proc_t);
 }
 
 static const rb_data_type_t proc_data_type = {
     "proc",
     {
 	proc_mark,
-	proc_free,
+	RUBY_TYPED_DEFAULT_FREE,
 	proc_memsize,
     },
     NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
Index: vm.c
===================================================================
--- vm.c	(revision 47563)
+++ vm.c	(revision 47564)
@@ -350,57 +350,41 @@ ruby_vm_run_at_exit_hooks(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/vm.c#L350
 static void
 env_mark(void * const ptr)
 {
-    RUBY_MARK_ENTER("env");
-    if (ptr) {
-	const rb_env_t * const env = ptr;
-
-	/* TODO: should mark more restricted range */
-	RUBY_GC_INFO("env->env\n");
-	rb_gc_mark_values((long)env->env_size, env->env);
-
-	RUBY_GC_INFO("env->prev_envval\n");
-	RUBY_MARK_UNLESS_NULL(env->prev_envval);
-	RUBY_MARK_UNLESS_NULL(env->block.self);
-	RUBY_MARK_UNLESS_NULL(env->block.proc);
-
-	if (env->block.iseq) {
-	    if (BUILTIN_TYPE(env->block.iseq) == T_NODE) {
-		RUBY_MARK_UNLESS_NULL((VALUE)env->block.iseq);
-	    }
-	    else {
-		RUBY_MARK_UNLESS_NULL(env->block.iseq->self);
-	    }
+    const rb_env_t * const env = ptr;
+
+    /* TODO: should mark more restricted range */
+    RUBY_GC_INFO("env->env\n");
+    rb_gc_mark_values((long)env->env_size, env->env);
+
+    RUBY_GC_INFO("env->prev_envval\n");
+    RUBY_MARK_UNLESS_NULL(env->prev_envval);
+    RUBY_MARK_UNLESS_NULL(env->block.self);
+    RUBY_MARK_UNLESS_NULL(env->block.proc);
+
+    if (env->block.iseq) {
+	if (BUILTIN_TYPE(env->block.iseq) == T_NODE) {
+	    RUBY_MARK_UNLESS_NULL((VALUE)env->block.iseq);
+	}
+	else {
+	    RUBY_MARK_UNLESS_NULL(env->block.iseq->self);
 	}
     }
     RUBY_MARK_LEAVE("env");
 }
 
-static void
-env_free(void * const ptr)
-{
-    RUBY_FREE_ENTER("env");
-    if (ptr) {
-	ruby_xfree(ptr);
-    }
-    RUBY_FREE_LEAVE("env");
-}
-
 static size_t
 env_memsize(const void *ptr)
 {
-    if (ptr) {
-	const rb_env_t * const env = ptr;
-	size_t size = sizeof(rb_env_t);
+    const rb_env_t * const env = ptr;
+    size_t size = sizeof(rb_env_t);
 
-	size += (env->env_size - 1) * sizeof(VALUE);
-	return size;
-    }
-    return 0;
+    size += (env->env_size - 1) * sizeof(VALUE);
+    return size;
 }
 
 static const rb_data_type_t env_data_type = {
     "VM/env",
-    {env_mark, env_free, env_memsize,},
+    {env_mark, RUBY_TYPED_DEFAULT_FREE, env_memsize,},
     NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 

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

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