From a006741598ade7ce8293a73bb904683c3451ea93 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Mon, 6 May 2019 00:31:20 +0000
Subject: [PATCH] The Win32 implementation of strcasestr() defined here is
 currently very heavy-handed (performs strdup/malloc's and modifications of
 the strings), so a temporary hack is to perform a case-sensitive search
 (using the standard strstr() function) first. The results won't exactly match
 the traditional strstr() and the performance improvement is only for positive
 matches (where the correct case was guessed in the passed 'needle' string
 arg). TODO: re-write or copy a good/fast strcasestr() implementation for
 Win32 builds.

---
 src/xpdev/genwrap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c
index e5a055b22d..142a9a38e8 100644
--- a/src/xpdev/genwrap.c
+++ b/src/xpdev/genwrap.c
@@ -80,13 +80,16 @@ int DLLCALL safe_snprintf(char *dst, size_t size, const char *fmt, ...)
 
 #ifdef _MSC_VER
 /****************************************************************************/
-/* Case insensitive version of strstr()										*/
+/* Case insensitive version of strstr()	- currently heavy-handed			*/
 /****************************************************************************/
 char* DLLCALL strcasestr(const char* haystack, const char* needle)
 {
+	char* p = NULL;
+	/* temporary performance hack begin (warning: different behavior from traditional strcasestr): */
+	if((p = strstr(haystack, needle)) != NULL)
+		return p;
 	char* h = strdup(haystack);
 	char* n = strdup(needle);
-	char* p = NULL;
 	if(h != NULL && n != NULL)
 		p = strstr(strupr(h), strupr(n));
 	int offset = p - h;
-- 
GitLab