From 28639969ef6ca5deaf32c550151a7cd604cbf0b1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 28 May 2020 19:44:33 -0700 Subject: [PATCH] Use memcpy for copying digits --- include/fmt/format.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 123a9e26..f3ea2043 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2862,16 +2862,17 @@ class format_int { // "Three Optimization Tips for C++". See speed-test for a comparison. auto index = static_cast((value % 100) * 2); value /= 100; - *--ptr = detail::data::digits[index + 1]; - *--ptr = detail::data::digits[index]; + ptr -= 2; + // memcpy is faster than copying character by character. + memcpy(ptr, detail::data::digits + index, 2); } if (value < 10) { *--ptr = static_cast('0' + value); return ptr; } auto index = static_cast(value * 2); - *--ptr = detail::data::digits[index + 1]; - *--ptr = detail::data::digits[index]; + ptr -= 2; + memcpy(ptr, detail::data::digits + index, 2); return ptr; }