summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-23 15:44:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-23 15:44:05 +0000
commit33c9c0005b28c9897ef03ac595047e423221103e (patch)
tree13776042768313657c670b73f3e405a060474581 /file.c
parent3e7ba606a2b1198d3db40db359a31442fd7f6acc (diff)
* 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
Diffstat (limited to 'file.c')
-rw-r--r--file.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/file.c b/file.c
index b159256..5215af7 100644
--- a/file.c
+++ b/file.c
@@ -1527,14 +1527,16 @@ chompdirsep(path)
return (char *)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() (\
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);
}