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

Commit d594bb4

Browse files
committed
Move radix to template parameter in unsignedToTempString
1 parent b8fb84c commit d594bb4

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

src/core/demangle.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pure @safe:
279279

280280
UnsignedStringBuf buf = void;
281281

282-
auto s = unsignedToTempString(val, buf, 16);
282+
auto s = unsignedToTempString!16(val, buf);
283283
int slen = cast(int)s.length;
284284
if (slen < width)
285285
{

src/core/internal/abort.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ void abort(scope string msg, scope string filename = __FILE__, size_t line = __L
4848
UnsignedStringBuf strbuff = void;
4949

5050
// write an appropriate message, then abort the program
51-
writeStr("Aborting from ", filename, "(", line.unsignedToTempString(strbuff, 10), ") ", msg);
51+
writeStr("Aborting from ", filename, "(", line.unsignedToTempString(strbuff), ") ", msg);
5252
c_abort();
5353
}

src/core/internal/string.d

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Params:
2828
Returns:
2929
The unsigned integer value as a string of characters
3030
*/
31-
char[] unsignedToTempString()(ulong value, return scope char[] buf, uint radix = 10) @safe
31+
char[] unsignedToTempString(uint radix = 10)(ulong value, return scope char[] buf) @safe
3232
{
3333
if (radix < 2)
3434
// not a valid radix, just return an empty string
@@ -77,46 +77,46 @@ Params:
7777
Returns:
7878
The unsigned integer value as a string of characters
7979
*/
80-
auto unsignedToTempString()(ulong value, uint radix = 10) @safe
80+
auto unsignedToTempString(uint radix = 10)(ulong value) @safe
8181
{
8282
TempStringNoAlloc!() result = void;
83-
result._len = unsignedToTempString(value, result._buf, radix).length & 0xff;
83+
result._len = unsignedToTempString!radix(value, result._buf).length & 0xff;
8484
return result;
8585
}
8686

8787
unittest
8888
{
8989
UnsignedStringBuf buf;
90-
assert(0.unsignedToTempString(buf, 10) == "0");
91-
assert(1.unsignedToTempString(buf, 10) == "1");
92-
assert(12.unsignedToTempString(buf, 10) == "12");
93-
assert(0x12ABCF .unsignedToTempString(buf, 16) == "12abcf");
94-
assert(long.sizeof.unsignedToTempString(buf, 10) == "8");
95-
assert(uint.max.unsignedToTempString(buf, 10) == "4294967295");
96-
assert(ulong.max.unsignedToTempString(buf, 10) == "18446744073709551615");
90+
assert(0.unsignedToTempString(buf) == "0");
91+
assert(1.unsignedToTempString(buf) == "1");
92+
assert(12.unsignedToTempString(buf) == "12");
93+
assert(0x12ABCF .unsignedToTempString!16(buf) == "12abcf");
94+
assert(long.sizeof.unsignedToTempString(buf) == "8");
95+
assert(uint.max.unsignedToTempString(buf) == "4294967295");
96+
assert(ulong.max.unsignedToTempString(buf) == "18446744073709551615");
9797

9898
// use stack allocated struct version
99-
assert(0.unsignedToTempString(10) == "0");
99+
assert(0.unsignedToTempString == "0");
100100
assert(1.unsignedToTempString == "1");
101101
assert(12.unsignedToTempString == "12");
102-
assert(0x12ABCF .unsignedToTempString(16) == "12abcf");
102+
assert(0x12ABCF .unsignedToTempString!16 == "12abcf");
103103
assert(long.sizeof.unsignedToTempString == "8");
104104
assert(uint.max.unsignedToTempString == "4294967295");
105105
assert(ulong.max.unsignedToTempString == "18446744073709551615");
106106

107107
// test bad radices
108-
assert(100.unsignedToTempString(buf, 1) == "");
109-
assert(100.unsignedToTempString(buf, 0) == "");
108+
assert(100.unsignedToTempString!1(buf) == "");
109+
assert(100.unsignedToTempString!0(buf) == "");
110110
}
111111

112112
alias SignedStringBuf = char[20];
113113

114-
char[] signedToTempString(long value, return scope char[] buf, uint radix = 10) @safe
114+
char[] signedToTempString(uint radix = 10)(long value, return scope char[] buf) @safe
115115
{
116116
bool neg = value < 0;
117117
if (neg)
118118
value = cast(ulong)-value;
119-
auto r = unsignedToTempString(value, buf, radix);
119+
auto r = unsignedToTempString!radix(value, buf);
120120
if (neg)
121121
{
122122
// about to do a slice without a bounds check
@@ -127,12 +127,12 @@ char[] signedToTempString(long value, return scope char[] buf, uint radix = 10)
127127
return r;
128128
}
129129

130-
auto signedToTempString(long value, uint radix = 10) @safe
130+
auto signedToTempString(uint radix = 10)(long value) @safe
131131
{
132132
bool neg = value < 0;
133133
if (neg)
134134
value = cast(ulong)-value;
135-
auto r = unsignedToTempString(value, radix);
135+
auto r = unsignedToTempString!radix(value);
136136
if (neg)
137137
{
138138
r._len++;

src/core/internal/util/array.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ private void _enforceSameLength(const char[] action,
4141
string msg = "Array lengths don't match for ";
4242
msg ~= action;
4343
msg ~= ": ";
44-
msg ~= length1.unsignedToTempString(tmpBuff, 10);
44+
msg ~= length1.unsignedToTempString(tmpBuff);
4545
msg ~= " != ";
46-
msg ~= length2.unsignedToTempString(tmpBuff, 10);
46+
msg ~= length2.unsignedToTempString(tmpBuff);
4747
assert(0, msg);
4848
}
4949

@@ -59,9 +59,9 @@ private void _enforceNoOverlap(const char[] action,
5959
string msg = "Overlapping arrays in ";
6060
msg ~= action;
6161
msg ~= ": ";
62-
msg ~= overlappedBytes.unsignedToTempString(tmpBuff, 10);
62+
msg ~= overlappedBytes.unsignedToTempString(tmpBuff);
6363
msg ~= " byte(s) overlap of ";
64-
msg ~= bytes.unsignedToTempString(tmpBuff, 10);
64+
msg ~= bytes.unsignedToTempString(tmpBuff);
6565
assert(0, msg);
6666
}
6767

src/core/time.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ public:
15841584
unit = "μs";
15851585
else
15861586
unit = plural ? units : units[0 .. $-1];
1587-
res ~= signedToTempString(val, 10);
1587+
res ~= signedToTempString(val);
15881588
res ~= " ";
15891589
res ~= unit;
15901590
}
@@ -1808,7 +1808,7 @@ unittest
18081808
static if (is(F == int) || is(F == long))
18091809
return signedToTempString(val, 10);
18101810
else
1811-
return unsignedToTempString(val, 10);
1811+
return unsignedToTempString(val);
18121812
}
18131813

18141814
foreach (F; AliasSeq!(int,uint,long,ulong,float,double,real))
@@ -2405,7 +2405,7 @@ assert(before + timeElapsed == after);
24052405
string toString() const pure nothrow
24062406
{
24072407
static if (clockType == ClockType.normal)
2408-
return "MonoTime(" ~ signedToTempString(_ticks, 10) ~ " ticks, " ~ signedToTempString(ticksPerSecond, 10) ~ " ticks per second)";
2408+
return "MonoTime(" ~ signedToTempString(_ticks) ~ " ticks, " ~ signedToTempString(ticksPerSecond) ~ " ticks per second)";
24092409
else
24102410
return "MonoTimeImpl!(ClockType." ~ _clockName ~ ")(" ~ signedToTempString(_ticks, 10) ~ " ticks, " ~
24112411
signedToTempString(ticksPerSecond, 10) ~ " ticks per second)";
@@ -3972,7 +3972,7 @@ string doubleToString(double value) @safe pure nothrow
39723972
else
39733973
result = signedToTempString(cast(long)value, 10).idup;
39743974
result ~= '.';
3975-
result ~= unsignedToTempString(cast(ulong)(_abs((value - cast(long)value) * 1_000_000) + .5), 10);
3975+
result ~= unsignedToTempString(cast(ulong)(_abs((value - cast(long)value) * 1_000_000) + .5));
39763976

39773977
while (result[$-1] == '0')
39783978
result = result[0 .. $-1];

src/object.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class TypeInfo_StaticArray : TypeInfo
630630
import core.internal.string : unsignedToTempString;
631631

632632
char[20] tmpBuff = void;
633-
return value.toString() ~ "[" ~ unsignedToTempString(len, tmpBuff, 10) ~ "]";
633+
return value.toString() ~ "[" ~ unsignedToTempString(len, tmpBuff) ~ "]";
634634
}
635635

636636
override bool opEquals(Object o)
@@ -2008,7 +2008,7 @@ class Throwable : Object
20082008

20092009
sink(typeid(this).name);
20102010
sink("@"); sink(file);
2011-
sink("("); sink(unsignedToTempString(line, tmpBuff, 10)); sink(")");
2011+
sink("("); sink(unsignedToTempString(line, tmpBuff)); sink(")");
20122012

20132013
if (msg.length)
20142014
{

0 commit comments

Comments
 (0)