Optimization ???
rumbu
rumbu at rumbu.ro
Fri Feb 21 15:01:40 PST 2014
D version of to!string(uint):
size_t index = 12;
char[12] buffer = void;
uint div = void;
uint mod = void;
char baseChar = 'A';
do {
div = cast(uint)(mValue / 10);
mod = mValue % 10 + '0';
buffer[--index] = cast(char)mod;
mValue = div;
} while (mValue);
return cast(string)buffer[index .. $].dup;
C# version of uint.ToString() (in fact Int32ToDecChars written in
C++):
//p is a reusable buffer;
wchar_t* COMNumber::Int32ToDecChars(wchar_t* p, unsigned int
value, int digits)
{
while (--digits >= 0 || value != 0) {
*--p = value % 10 + '0';
value /= 10;
}
return p;
}
//COMString::NewString(p,...) is called afterwards to obtain a c#
string.
More information about the Digitalmars-d-learn
mailing list