diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-10-22 04:27:48 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-10-22 04:27:48 +0000 |
| commit | 8e14695b2d7c7cb895650236e413cdec93757c40 (patch) | |
| tree | 0854c78b206cd0d296e621c9db56bac72268d8e5 /time.c | |
| parent | ac6af07321fe42612d4d54a8c5795e02cd39036a (diff) | |
| download | ruby-8e14695b2d7c7cb895650236e413cdec93757c40.tar.gz ruby-8e14695b2d7c7cb895650236e413cdec93757c40.tar.xz ruby-8e14695b2d7c7cb895650236e413cdec93757c40.zip | |
* time.c (rb_strftime): removed meaningless volatile modifiers, and
concatenate successive nul characters at once. [ruby-dev:27472]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
| -rw-r--r-- | time.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -1670,12 +1670,11 @@ time_to_a(VALUE time) #define SMALLBUF 100 static int -rb_strftime(char ** volatile buf, - char * volatile format, - struct tm * volatile time) +rb_strftime(char **buf, + const char *format, + struct tm *time) { - volatile int size; - int len, flen; + int size, len, flen; (*buf)[0] = '\0'; flen = strlen(format); @@ -1746,8 +1745,8 @@ static VALUE time_strftime(VALUE time, VALUE format) { struct time_object *tobj; - char buffer[SMALLBUF]; - char *fmt, *buf = buffer; + char buffer[SMALLBUF], *buf = buffer; + const char *fmt; long len; VALUE str; @@ -1764,19 +1763,19 @@ time_strftime(VALUE time, VALUE format) } else if (strlen(fmt) < len) { /* Ruby string may contain \0's. */ - char *p = fmt, *pe = fmt + len; + const char *p = fmt, *pe = fmt + len; str = rb_str_new(0, 0); while (p < pe) { len = rb_strftime(&buf, p, &tobj->tm); rb_str_cat(str, buf, len); p += strlen(p) + 1; - if (p <= pe) - rb_str_cat(str, "\0", 1); if (buf != buffer) { free(buf); buf = buffer; } + for (fmt = p; p < pe && !*p; ++p); + if (p > fmt) rb_str_cat(str, fmt, p - fmt); } return str; } |
