Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 237a465

Browse files
committed
Review: improve use of radix in control flow
1 parent 07b5c36 commit 237a465

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/core/internal/string.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ if (radix >= 2 && radix <= 16)
3434
size_t i = buf.length;
3535
do
3636
{
37+
uint x = void;
3738
if (value < radix)
3839
{
39-
ubyte x = cast(ubyte)value;
40-
buf[--i] = cast(char)((x < 10) ? x + '0' : x - 10 + 'a');
41-
break;
40+
x = cast(uint)value;
41+
value = 0;
4242
}
4343
else
4444
{
45-
ubyte x = cast(ubyte)(value % radix);
46-
value = value / radix;
47-
buf[--i] = cast(char)((x < 10) ? x + '0' : x - 10 + 'a');
45+
x = cast(uint)(value % radix);
46+
value /= radix;
4847
}
48+
buf[--i] = cast(char)((radix <= 10 || x < 10) ? x + '0' : x - 10 + 'a');
4949
} while (value);
5050
return buf[i .. $];
5151
}

0 commit comments

Comments
 (0)