mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-08 23:55:03 +00:00
Speed up raw_ostream::<<(unsigned long long) for 32-bit systems by doing most
div/mods in 32-bits. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79375 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c0823fe7c6
commit
3b3de924f5
@ -125,19 +125,24 @@ raw_ostream &raw_ostream::operator<<(long N) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
raw_ostream &raw_ostream::operator<<(unsigned long long N) {
|
raw_ostream &raw_ostream::operator<<(unsigned long long N) {
|
||||||
// Output using 32-bit div/mod when possible.
|
// Handle simple case when value fits in long already.
|
||||||
if (N == static_cast<unsigned long>(N))
|
if (N == static_cast<unsigned long>(N))
|
||||||
return this->operator<<(static_cast<unsigned long>(N));
|
return this->operator<<(static_cast<unsigned long>(N));
|
||||||
|
|
||||||
char NumberBuffer[20];
|
// Otherwise divide into at two or three 10**9 chunks and write out using
|
||||||
char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
|
// long div/mod, this is substantially faster on a 32-bit system.
|
||||||
char *CurPtr = EndPtr;
|
unsigned long Top = 0, Mid = 0, Bot = N % 1000000000;
|
||||||
|
N /= 1000000000;
|
||||||
|
if (N > 1000000000) {
|
||||||
|
Mid = N % 1000000000;
|
||||||
|
Top = N / 1000000000;
|
||||||
|
} else
|
||||||
|
Mid = N;
|
||||||
|
|
||||||
while (N) {
|
if (Top)
|
||||||
*--CurPtr = '0' + char(N % 10);
|
this->operator<<(static_cast<unsigned long>(Top));
|
||||||
N /= 10;
|
this->operator<<(static_cast<unsigned long>(Mid));
|
||||||
}
|
return this->operator<<(static_cast<unsigned long>(Bot));
|
||||||
return write(CurPtr, EndPtr-CurPtr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_ostream &raw_ostream::operator<<(long long N) {
|
raw_ostream &raw_ostream::operator<<(long long N) {
|
||||||
|
Loading…
Reference in New Issue
Block a user