From ae6b87d646cf8633ae690c81078fc2376750db7a Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 24 Oct 2021 21:48:02 +0200 Subject: [PATCH] Optimization in case of small constant strings --- m-string.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/m-string.h b/m-string.h index bc85021b..75a86128 100644 --- a/m-string.h +++ b/m-string.h @@ -269,6 +269,9 @@ m_str1ng_fit2size (string_t v, size_t size_alloc) // Note: this function may be called in context where the contract // is not fullfilled. const size_t old_alloc = string_capacity(v); + // This line enables the compiler to completly remove this function + // for very short constant strings. + M_ASSUME(old_alloc >= sizeof (string_heap_ct) - 1); if (M_UNLIKELY (size_alloc > old_alloc)) { size_t alloc = size_alloc + size_alloc / 2; if (M_UNLIKELY (alloc <= old_alloc)) {