mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 18:57:34 +02:00
Use memcpy for copying digits
This commit is contained in:
@ -2862,16 +2862,17 @@ class format_int {
|
|||||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||||
auto index = static_cast<unsigned>((value % 100) * 2);
|
auto index = static_cast<unsigned>((value % 100) * 2);
|
||||||
value /= 100;
|
value /= 100;
|
||||||
*--ptr = detail::data::digits[index + 1];
|
ptr -= 2;
|
||||||
*--ptr = detail::data::digits[index];
|
// memcpy is faster than copying character by character.
|
||||||
|
memcpy(ptr, detail::data::digits + index, 2);
|
||||||
}
|
}
|
||||||
if (value < 10) {
|
if (value < 10) {
|
||||||
*--ptr = static_cast<char>('0' + value);
|
*--ptr = static_cast<char>('0' + value);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
auto index = static_cast<unsigned>(value * 2);
|
auto index = static_cast<unsigned>(value * 2);
|
||||||
*--ptr = detail::data::digits[index + 1];
|
ptr -= 2;
|
||||||
*--ptr = detail::data::digits[index];
|
memcpy(ptr, detail::data::digits + index, 2);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user