summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-27 03:55:08 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-27 03:55:08 (GMT)
commitd1e2d6a9c52749912e8239d51b6beb5c6d9de943 (patch)
tree11ec861ad573f24223f0479012a6e11c93481868 /sprintf.c
parentee2f3c6def27ae7ea069ac8a2472ce2e80bcbb5b (diff)
sprintf.c: simplify
* sprintf.c (rb_str_format): remove repeated calculations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c11
1 files changed, 2 insertions, 9 deletions
diff --git a/sprintf.c b/sprintf.c
index f0c2f8d..5c1f778 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1034,7 +1034,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
{
VALUE val = GETARG(), num, den;
int sign = (flags&FPLUS) ? 1 : 0, zero = 0;
- long len, done = 0;
+ long len, done = blen;
int prefix = 0;
if (FIXNUM_P(val) || RB_TYPE_P(val, T_BIGNUM)) {
den = INT2FIX(1);
@@ -1077,39 +1077,32 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (sign || (flags&FSPACE)) {
buf[blen++] = sign > 0 ? '+' : sign < 0 ? '-' : ' ';
prefix++;
- done++;
}
len = RSTRING_LEN(val) + zero;
t = RSTRING_PTR(val);
if (len > prec) {
memcpy(&buf[blen], t, len - prec);
blen += len - prec;
- done += len - prec;
}
else {
buf[blen++] = '0';
- done++;
}
if (prec > 0) {
buf[blen++] = '.';
- done++;
}
if (zero) {
FILL('0', zero);
- done += zero;
}
else if (prec > len) {
FILL('0', prec - len);
memcpy(&buf[blen], t, len);
blen += len;
- done += prec;
}
else if (prec > 0) {
memcpy(&buf[blen], t + len - prec, prec);
blen += prec;
- done += prec;
}
- if ((flags & FWIDTH) && width > done) {
+ if ((flags & FWIDTH) && width > (done = blen - done)) {
int fill = ' ';
long shifting = 0;
if (!(flags&FMINUS)) {