From 31caeec248f40459b3efdadde72f586d8ed4dfac Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 31 May 2025 21:51:48 +0100 Subject: [PATCH] Optimisation of strings --- include/etl/string_utilities.h | 93 ---------------------------------- 1 file changed, 93 deletions(-) diff --git a/include/etl/string_utilities.h b/include/etl/string_utilities.h index b824cd28..46ead0bf 100644 --- a/include/etl/string_utilities.h +++ b/include/etl/string_utilities.h @@ -883,99 +883,6 @@ namespace etl etl::transform(itr, s.end(), itr, ::tolower); } - - //*************************************************************************** - /// str_n_copy - /// Copies from src to dst until either n characters have been copied, or a - /// terminating null is found. - /// Null terminates the destination if less than n characters have been copied. - /// Returns a str_n_copy_result. - //*************************************************************************** - struct str_n_copy_result - { - size_t count; - bool truncated; - bool terminated; - }; - - template - str_n_copy_result str_n_copy(const T* src, size_t n, T* dst) - { - if ((src == ETL_NULLPTR) || (dst == ETL_NULLPTR)) - { - return { 0, false, false }; - } - - size_t count = 0; - -#if defined(__GNUC__) || defined(_MSC_VER) - // Use restrict if available, for better optimization - const T* __restrict s = src; - T* __restrict d = dst; -#else - const T* s = src; - T* d = dst; -#endif - - // Copy in blocks of 4 for loop unrolling - count += 4; - while (count <= n) - { - if (s[0] == 0) - { - break; - } - - d[0] = s[0]; - - if (s[1] == 0) - { - count += 1; - d[1] = 0; - return { count, false, true }; - } - - d[1] = s[1]; - - if (s[2] == 0) - { - count += 2; d[2] = 0; - return { count, false, true }; - } - - d[2] = s[2]; - - if (s[3] == 0) - { - count += 3; - d[3] = 0; - return { count, false, true }; - } - - d[3] = s[3]; - s += 4; - d += 4; - count += 4; - } - - // Copy remaining - while ((count < n) && (*s != 0)) - { - *d++ = *s++; - ++count; - } - - // - if (count <= n) - { - *d = 0; - return { count, false, true }; - } - else - { - return { count, *s != 0, false }; - } - } } #include "private/minmax_pop.h"