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

ruby-changes:38919

From: normal <ko1@a...>
Date: Tue, 23 Jun 2015 09:49:40 +0900 (JST)
Subject: [ruby-changes:38919] normal:r51000 (trunk): dir.c (check_dirname): avoid volatile, use return value

normal	2015-06-23 09:49:26 +0900 (Tue, 23 Jun 2015)

  New Revision: 51000

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

  Log:
    dir.c (check_dirname): avoid volatile, use return value
    
    volatile is unnecessary since we use rb_sys_fail_path nowadays
    and that prevents the path argument from being GC-ed.
    Using a return value instead of modifying the argument directly
    simplifies the generated code (on 32-bit x86):
    
     text    data     bss     dec     hex filename
    20744      40      20   20804    5144 dir.o-orig
    20720      40      20   20780    512c dir.o
    
    * dir.c (check_dirname): avoid volatile, use return value
      (dir_s_chroot, dir_s_mkdir, dir_s_rmdir): adjust callers

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50999)
+++ ChangeLog	(revision 51000)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 23 09:48:34 2015  Eric Wong  <e@8...>
+
+	* dir.c (check_dirname): avoid volatile, use return value
+	  (dir_s_chroot, dir_s_mkdir, dir_s_rmdir): adjust callers
+
 Tue Jun 23 06:37:10 2015  Eric Wong  <e@8...>
 
 	* struct.c (struct_ivar_get): cache member definition in a subclass
Index: dir.c
===================================================================
--- dir.c	(revision 50999)
+++ dir.c	(revision 51000)
@@ -1004,10 +1004,10 @@ dir_s_getwd(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L1004
     return rb_dir_getwd();
 }
 
-static void
-check_dirname(volatile VALUE *dir)
+static VALUE
+check_dirname(VALUE dir)
 {
-    VALUE d = *dir;
+    VALUE d = dir;
     char *path, *pend;
     long len;
     rb_encoding *enc;
@@ -1020,7 +1020,7 @@ check_dirname(volatile VALUE *dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L1020
     if (pend - path < len) {
 	d = rb_str_subseq(d, 0, pend - path);
     }
-    *dir = rb_str_encode_ospath(d);
+    return rb_str_encode_ospath(d);
 }
 
 #if defined(HAVE_CHROOT)
@@ -1036,7 +1036,7 @@ check_dirname(volatile VALUE *dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L1036
 static VALUE
 dir_s_chroot(VALUE dir, VALUE path)
 {
-    check_dirname(&path);
+    path = check_dirname(path);
     if (chroot(RSTRING_PTR(path)) == -1)
 	rb_sys_fail_path(path);
 
@@ -1074,7 +1074,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/dir.c#L1074
 	mode = 0777;
     }
 
-    check_dirname(&path);
+    path = check_dirname(path);
     if (mkdir(RSTRING_PTR(path), mode) == -1)
 	rb_sys_fail_path(path);
 
@@ -1093,7 +1093,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/dir.c#L1093
 static VALUE
 dir_s_rmdir(VALUE obj, VALUE dir)
 {
-    check_dirname(&dir);
+    dir = check_dirname(dir);
     if (rmdir(RSTRING_PTR(dir)) < 0)
 	rb_sys_fail_path(dir);
 

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

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