зеркало из https://github.com/github/ruby.git
* file.c (file_expand_path): performance improvement.
[ruby-talk:79748] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3e7ba606a2
Коммит
33c9c0005b
|
@ -1,3 +1,8 @@
|
|||
Sun Aug 24 00:44:03 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* file.c (file_expand_path): performance improvement.
|
||||
[ruby-talk:79748]
|
||||
|
||||
Sat Aug 23 18:56:53 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/nkf/nkf.c (rb_nkf_putchar): should use rb_str_resize() to just
|
||||
|
|
17
file.c
17
file.c
|
@ -1527,14 +1527,16 @@ chompdirsep(path)
|
|||
return (char *)path;
|
||||
}
|
||||
|
||||
#define BUFCHECK(cond) while (cond) {\
|
||||
#define BUFCHECK(cond) do {\
|
||||
long bdiff = p - buf;\
|
||||
while (cond) {\
|
||||
buflen *= 2;\
|
||||
}\
|
||||
rb_str_resize(result, buflen);\
|
||||
buf = RSTRING(result)->ptr;\
|
||||
p = buf + bdiff;\
|
||||
pend = buf + buflen;\
|
||||
}
|
||||
} while (0)
|
||||
|
||||
#define BUFINIT() (\
|
||||
p = buf = RSTRING(result)->ptr,\
|
||||
|
@ -1552,7 +1554,7 @@ file_expand_path(fname, dname, result)
|
|||
VALUE fname, dname, result;
|
||||
{
|
||||
char *s, *buf, *b, *p, *pend, *root;
|
||||
long buflen;
|
||||
long buflen, dirlen;
|
||||
int tainted;
|
||||
|
||||
s = StringValuePtr(fname);
|
||||
|
@ -1566,7 +1568,8 @@ file_expand_path(fname, dname, result)
|
|||
if (!dir) {
|
||||
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__
|
||||
for (p = buf; *p; p = CharNext(p)) {
|
||||
|
@ -1596,7 +1599,8 @@ file_expand_path(fname, dname, result)
|
|||
endpwent();
|
||||
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);
|
||||
endpwent();
|
||||
|
@ -1644,7 +1648,8 @@ file_expand_path(fname, dname, result)
|
|||
char *dir = my_getcwd();
|
||||
|
||||
tainted = 1;
|
||||
BUFCHECK(strlen(dir) > buflen);
|
||||
dirlen = strlen(dir);
|
||||
BUFCHECK(dirlen > buflen);
|
||||
strcpy(buf, dir);
|
||||
free(dir);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче