[BUG] File.expand_path regression in 1.8.0

File.expand_path seems to be much slower under ruby 1.8.0 when compared to
ruby 1.6.8, tested under debian unstable

$ ruby -v
ruby 1.6.8 (2003-07-09) [i386-linux]

$ ruby1.8 -v
ruby 1.8.0 (2003-08-10) [i386-linux]

Testing code:

1.upto(100000) do
File.expand_path(“linux/blabla”)
end

$ time ruby bench.rb

real 0m0.737s
user 0m0.590s
sys 0m0.150s

$ time ruby1.8 bench.rb

real 0m4.370s
user 0m1.590s
sys 0m2.740s

Idan.

File.expand_path in 1.8 does a lot more than 1.6, for example, UNC
support, removing path length limit, robustness, etc.

						matz.
···

In message “[BUG] File.expand_path regression in 1.8.0” on 03/08/21, Idan Sofer idan@idanso.dyndns.org writes:

File.expand_path seems to be much slower under ruby 1.8.0 when compared to
ruby 1.6.8, tested under debian unstable

Hi,

···

At Sat, 23 Aug 2003 23:45:42 +0900, Yukihiro Matsumoto wrote:

File.expand_path seems to be much slower under ruby 1.8.0 when compared to
ruby 1.6.8, tested under debian unstable

File.expand_path in 1.8 does a lot more than 1.6, for example, UNC
support, removing path length limit, robustness, etc.

This would improve it a little, though it can not defeat 1.6
still.

Index: file.c

RCS file: /cvs/ruby/src/ruby/file.c,v
retrieving revision 1.156
diff -u -2 -p -r1.156 file.c
— file.c 15 Aug 2003 03:01:52 -0000 1.156
+++ file.c 23 Aug 2003 09:33:26 -0000
@@ -1528,12 +1528,14 @@ chompdirsep(path)
}

-#define BUFCHECK(cond) while (cond) {
+#define BUFCHECK(cond) do {
long bdiff = p - buf;\

  • buflen *= 2;\
  • while (cond) {\
  • buflen *= 2;\
  • }
    rb_str_resize(result, buflen);
    buf = RSTRING(result)->ptr;
    p = buf + bdiff;
    pend = buf + buflen;
    -}
    +} while (0)

#define BUFINIT() (
@@ -1553,5 +1555,5 @@ file_expand_path(fname, dname, result)
{
char *s, *buf, *b, *p, *pend, *root;

  • long buflen;
  • long buflen, dirlen;
    int tainted;

@@ -1567,5 +1569,6 @@ file_expand_path(fname, dname, result)
rb_raise(rb_eArgError, “couldn’t find HOME environment – expanding `%s’”, s);
}

  •   BUFCHECK(strlen(dir) > buflen);
    
  •   dirlen = strlen(dir);
    
  •   BUFCHECK(dirlen > buflen);
      strcpy(buf, dir);
    

#if defined DOSISH || defined CYGWIN
@@ -1597,5 +1600,6 @@ file_expand_path(fname, dname, result)
rb_raise(rb_eArgError, “user %s doesn’t exist”, buf);
}

  •   BUFCHECK(strlen(pwPtr->pw_dir) > buflen);
    
  •   dirlen = strlen(pwPtr->pw_dir);
    
  •   BUFCHECK(dirlen > buflen);
      strcpy(buf, pwPtr->pw_dir);
      p = buf + strlen(pwPtr->pw_dir);
    

@@ -1645,5 +1649,6 @@ file_expand_path(fname, dname, result)

    tainted = 1;
  •   BUFCHECK(strlen(dir) > buflen);
    
  •   dirlen = strlen(dir);
    
  •   BUFCHECK(dirlen > buflen);
      strcpy(buf, dir);
      free(dir);
    


Nobu Nakada

Hi,

···

In message “Re: [BUG] File.expand_path regression in 1.8.0” on 03/08/24, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

This would improve it a little, though it can not defeat 1.6
still.

I like this fix. Commit this please.

						matz.