1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-06-23 00:49:26 +00:00
parent 099e6e7817
commit 3fe2773c73
2 changed files with 12 additions and 7 deletions

View file

@ -1,3 +1,8 @@
Tue Jun 23 09:48:34 2015 Eric Wong <e@80x24.org>
* 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@80x24.org> Tue Jun 23 06:37:10 2015 Eric Wong <e@80x24.org>
* struct.c (struct_ivar_get): cache member definition in a subclass * struct.c (struct_ivar_get): cache member definition in a subclass

14
dir.c
View file

@ -1004,10 +1004,10 @@ dir_s_getwd(VALUE dir)
return rb_dir_getwd(); return rb_dir_getwd();
} }
static void static VALUE
check_dirname(volatile VALUE *dir) check_dirname(VALUE dir)
{ {
VALUE d = *dir; VALUE d = dir;
char *path, *pend; char *path, *pend;
long len; long len;
rb_encoding *enc; rb_encoding *enc;
@ -1020,7 +1020,7 @@ check_dirname(volatile VALUE *dir)
if (pend - path < len) { if (pend - path < len) {
d = rb_str_subseq(d, 0, pend - path); d = rb_str_subseq(d, 0, pend - path);
} }
*dir = rb_str_encode_ospath(d); return rb_str_encode_ospath(d);
} }
#if defined(HAVE_CHROOT) #if defined(HAVE_CHROOT)
@ -1036,7 +1036,7 @@ check_dirname(volatile VALUE *dir)
static VALUE static VALUE
dir_s_chroot(VALUE dir, VALUE path) dir_s_chroot(VALUE dir, VALUE path)
{ {
check_dirname(&path); path = check_dirname(path);
if (chroot(RSTRING_PTR(path)) == -1) if (chroot(RSTRING_PTR(path)) == -1)
rb_sys_fail_path(path); rb_sys_fail_path(path);
@ -1074,7 +1074,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
mode = 0777; mode = 0777;
} }
check_dirname(&path); path = check_dirname(path);
if (mkdir(RSTRING_PTR(path), mode) == -1) if (mkdir(RSTRING_PTR(path), mode) == -1)
rb_sys_fail_path(path); rb_sys_fail_path(path);
@ -1093,7 +1093,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
static VALUE static VALUE
dir_s_rmdir(VALUE obj, VALUE dir) dir_s_rmdir(VALUE obj, VALUE dir)
{ {
check_dirname(&dir); dir = check_dirname(dir);
if (rmdir(RSTRING_PTR(dir)) < 0) if (rmdir(RSTRING_PTR(dir)) < 0)
rb_sys_fail_path(dir); rb_sys_fail_path(dir);