From d7c5484036f7fbc35f5bf440887836005e477c01 Mon Sep 17 00:00:00 2001 From: SMcNeill Date: Thu, 2 Oct 2014 04:32:07 -0400 Subject: [PATCH] Replacement to stringcomp routine for less OS specific code, which executes faster overall for us anyway. --- .../user_mods/src/Steve Stuff/stringcomp.cpp | 55 +++++++------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/internal/c/parts/user_mods/src/Steve Stuff/stringcomp.cpp b/internal/c/parts/user_mods/src/Steve Stuff/stringcomp.cpp index 0b9c3e021..555082b4d 100644 --- a/internal/c/parts/user_mods/src/Steve Stuff/stringcomp.cpp +++ b/internal/c/parts/user_mods/src/Steve Stuff/stringcomp.cpp @@ -1,46 +1,32 @@ #include -#include -#ifdef QB64_WINDOWS -#define SNCMP(x,y,z) _memicmp((char *)x, (char *)y, z) -#else -#define SNCMP(x,y,z) strncasecmp((char *)x, (char *)y, z) -#endif int32 func__str_nc_compare(qbs *s1, qbs *s2) { - int32 i, limit, l1, l2; - l1 = s1->len; l2 = s2->len; //no need to get the length of these strings multiple times. + int32 limit, l1, l2; + int32 v1, v2; + unsigned char *c1=s1->chr, *c2=s2->chr; + + l1 = s1->len; l2 = s2->len; //no need to get the length of these strings multiple times. if (!l1) { if (l2) return -1; else return 0; //if one is a null string we known the answer already. } + if (!l2) return 1; if (l1<=l2) limit = l1; else limit = l2; //our limit is going to be the length of the smallest string. - #ifdef QB64_LINUX //by using memicmp with Windows, we don't need to do a precheck for CHR$(0) as it handles it just fine. - unsigned char *c1=s1->chr, *c2=s2->chr; - for (int32 i=0;ichr,qbs_lcase(s2)->chr,limit); //if so, then we cheat and use the lcase comparisons to get a valid result. - if (i<0) return -1; - if (i>0) return 1; - if (l1l2) return 1; - return 0; - } - c1++; - c2++; - } - #endif - - - i=SNCMP(s1->chr,s2->chr,limit); //check only to the length of the shortest string - if (i<0) return -1; //if the number is smaller by this point, say so - if (i>0) return 1; // if it's larger by this point, say so - //if the number is the same at this point, compare length. - //if the length of the first one is smaller, then the string is smaller. Otherwise the second one is the same string, or longer. - if (l1l2) return 1; - return 0; + for (int32 i=0;i64)&&(v1<91)) v1=v1|32; + if ((v2>64)&&(v2<91)) v2=v2|32; + if (v1v2) return 1; + c1++; + c2++; + } + + if (l1l1) return 1; + return 0; } -#undef SNCMP + int32 func__str_compare(qbs *s1, qbs *s2) { int32 i, limit, l1, l2; @@ -48,6 +34,7 @@ int32 func__str_compare(qbs *s1, qbs *s2) { if (!l1) { if (l2) return -1; else return 0; //if one is a null string we known the answer already. } + if (!l2) return 1; if (l1<=l2) limit = l1; else limit = l2; i=memcmp(s1->chr,s2->chr,limit); if (i<0) return -1;