From 7b7145f20a73bcef0b59bb69371efdbf16f8e336 Mon Sep 17 00:00:00 2001 From: Kp Date: Tue, 10 May 2022 01:58:55 +0000 Subject: [PATCH] Simplify zeroing callsign on copy-in Zero the entire array, then overwrite the leading portion with the received data. This permits the compiler to do a fixed number of large stores, instead of a variable number of small stores. --- common/main/player-callsign.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/common/main/player-callsign.h b/common/main/player-callsign.h index dd7c433f4..c60b53cd8 100644 --- a/common/main/player-callsign.h +++ b/common/main/player-callsign.h @@ -28,24 +28,23 @@ struct callsign_t { return std::tolower(static_cast(c)); } - callsign_t &zero_terminate(array_t::iterator i) - { - std::fill(i, end(a), 0); - return *this; - } callsign_t ©(const char *s, std::size_t N) { - return zero_terminate(std::copy_n(s, std::min(a.size() - 1, N), begin(a))); + a = {}; + std::copy_n(s, std::min(a.size() - 1, N), begin(a)); + return *this; } callsign_t ©_lower(const char *s, std::size_t N) { - return zero_terminate(std::transform(s, std::next(s, std::min(a.size() - 1, N)), begin(a), lower_predicate)); + a = {}; + std::transform(s, std::next(s, std::min(a.size() - 1, N)), begin(a), lower_predicate); + return *this; } void lower() { auto ba = begin(a); - std::transform(ba, std::prev(end(a)), ba, lower_predicate); a.back() = 0; + std::transform(ba, std::prev(end(a)), ba, lower_predicate); } [[nodiscard]] elements_t &buffer()