From: Michael Tremer Date: Tue, 28 Jan 2025 11:01:50 +0000 (+0000) Subject: strings: Use the branch prediction macros in potentially hot code X-Git-Tag: 0.9.30~328 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a3e12bb418764d5fccf7a6a3e661330211c41b2;p=pakfire.git strings: Use the branch prediction macros in potentially hot code Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/string.c b/src/pakfire/string.c index 3061da75..83bd6c22 100644 --- a/src/pakfire/string.c +++ b/src/pakfire/string.c @@ -46,11 +46,11 @@ int __pakfire_string_vformat(char* s, const size_t length, const char* format, v const ssize_t required = vsnprintf(s, length, format, args); // Catch any errors - if (required < 0) + if (unlikely(required < 0)) return -errno; // Check if the entire string could be written - if ((size_t)required >= length) + if (unlikely((size_t)required >= length)) return -ENOBUFS; // Success @@ -59,7 +59,7 @@ int __pakfire_string_vformat(char* s, const size_t length, const char* format, v int __pakfire_string_set(char* s, const size_t length, const char* value) { // If value is NULL or an empty, we will overwrite the buffer with just zeros - if (!value) { + if (unlikely(!value)) { *s = '\0'; return 0; } @@ -81,11 +81,11 @@ int __pakfire_string_set(char* s, const size_t length, const char* value) { int __pakfire_string_setn(char* s, const size_t length, const char* value, const size_t l) { // Fail if we don't have enough space - if (l >= length) + if (unlikely(l >= length)) return -ENOBUFS; // Copy the data - else if (l > 0) + if (likely(l > 0)) memcpy(s, value, l); // Terminate the result buffer