format.conv: Replace loop with copy()

This commit is contained in:
Eugen Wissner 2017-08-22 12:47:13 +02:00
parent 666d59c231
commit 0f1e53b4b9

View File

@ -17,6 +17,7 @@ module tanya.format.conv;
import std.traits; import std.traits;
import tanya.container.string; import tanya.container.string;
import tanya.memory; import tanya.memory;
import tanya.memory.op;
/** /**
* Thrown if a type conversion fails. * Thrown if a type conversion fails.
@ -669,32 +670,17 @@ package char[] number2String(T)(const T number, char[] buffer)
// Write the string. // Write the string.
char* bp = buffer.ptr; char* bp = buffer.ptr;
// Set sign. // Set the sign.
if (number < 0) if (number < 0)
{ {
*bp++ = '-'; *bp++ = '-';
} }
// Copy the string into the target buffer. // Copy the string into the target buffer.
uint n = l; int i = l;
while (n) copy(start[0 .. l], bp[0 .. l]);
{ bp += l;
int i = n;
n -= i;
while (i >= 4)
{
*cast(uint*) bp = *cast(uint*) start;
bp += 4;
start += 4;
i -= 4;
}
while (i)
{
*bp++ = *start++;
--i;
}
}
return buffer[0 .. bp - buffer.ptr]; return buffer[0 .. bp - buffer.ptr];
} }