From 1ce0c7d5afa2205cffa4f7db79a64c4130c5c402 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 20:10:01 +0100 Subject: [PATCH] fastcmp.h: mark fastcmp functions as pure this might let the compiler optimize aways subsequent calls in some cases strcmp etc from glibc also does it prayin nothin changes the locale at runtime lmao --- src/doomtype.h | 4 ++++ src/fastcmp.h | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index 198162852..fc55c9999 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -199,6 +199,7 @@ typedef int32_t boolean; #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) // >= GCC 3.1 #define FUNCDEAD __attribute__ ((deprecated)) #define FUNCINLINE __attribute__((always_inline)) + #define PUREFUNC __attribute__((pure)) #define FUNCNONNULL __attribute__((nonnull)) #endif @@ -264,6 +265,9 @@ typedef int32_t boolean; #ifndef ATTRNOINLINE #define ATTRNOINLINE #endif +#ifndef PUREFUNC +#define PUREFUNC +#endif /* Miscellaneous types that don't fit anywhere else (Can this be changed?) */ diff --git a/src/fastcmp.h b/src/fastcmp.h index 833b75330..91ac07211 100644 --- a/src/fastcmp.h +++ b/src/fastcmp.h @@ -7,14 +7,14 @@ extern "C" { // returns false if s != c // returns true if s == c -FUNCINLINE static ATTRINLINE boolean fasticmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fasticmp(const char *s, const char *c) { for (; *s && toupper(*s) == toupper(*c); s++, c++) ; return (*s == *c); // make sure both strings ended } // case-sensitive of the above -FUNCINLINE static ATTRINLINE boolean fastcmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fastcmp(const char *s, const char *c) { for (; *s && *s == *c; s++, c++) ; return (*s == *c); // make sure both strings ended @@ -22,7 +22,7 @@ FUNCINLINE static ATTRINLINE boolean fastcmp(const char *s, const char *c) // length-limited of the above // only true if both strings are at least l characters long AND match, case-sensitively! -FUNCINLINE static ATTRINLINE boolean fastncmp(const char *s, const char *c, UINT16 l) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fastncmp(const char *s, const char *c, UINT16 l) { for (; *s && *s == *c && --l; s++, c++) ; return !l; // make sure you reached the end