mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 05:48:40 +00:00
fast-path for string matching
This commit is contained in:
+19
-9
@@ -274,31 +274,41 @@ backslashed_from_str8(Arena *arena, String8 string)
|
|||||||
//~ rjf: String Matching
|
//~ rjf: String Matching
|
||||||
|
|
||||||
internal B32
|
internal B32
|
||||||
str8_match(String8 a, String8 b, StringMatchFlags flags){
|
str8_match(String8 a, String8 b, StringMatchFlags flags)
|
||||||
|
{
|
||||||
B32 result = 0;
|
B32 result = 0;
|
||||||
if (a.size == b.size || (flags & StringMatchFlag_RightSideSloppy)){
|
if(a.size == b.size && flags == 0)
|
||||||
B32 case_insensitive = (flags & StringMatchFlag_CaseInsensitive);
|
{
|
||||||
|
result = MemoryMatch(a.str, b.str, b.size);
|
||||||
|
}
|
||||||
|
else if(a.size == b.size || (flags & StringMatchFlag_RightSideSloppy))
|
||||||
|
{
|
||||||
|
B32 case_insensitive = (flags & StringMatchFlag_CaseInsensitive);
|
||||||
B32 slash_insensitive = (flags & StringMatchFlag_SlashInsensitive);
|
B32 slash_insensitive = (flags & StringMatchFlag_SlashInsensitive);
|
||||||
U64 size = Min(a.size, b.size);
|
U64 size = Min(a.size, b.size);
|
||||||
result = 1;
|
result = 1;
|
||||||
for (U64 i = 0; i < size; i += 1){
|
for(U64 i = 0; i < size; i += 1)
|
||||||
|
{
|
||||||
U8 at = a.str[i];
|
U8 at = a.str[i];
|
||||||
U8 bt = b.str[i];
|
U8 bt = b.str[i];
|
||||||
if (case_insensitive){
|
if(case_insensitive)
|
||||||
|
{
|
||||||
at = char_to_upper(at);
|
at = char_to_upper(at);
|
||||||
bt = char_to_upper(bt);
|
bt = char_to_upper(bt);
|
||||||
}
|
}
|
||||||
if (slash_insensitive){
|
if(slash_insensitive)
|
||||||
|
{
|
||||||
at = char_to_correct_slash(at);
|
at = char_to_correct_slash(at);
|
||||||
bt = char_to_correct_slash(bt);
|
bt = char_to_correct_slash(bt);
|
||||||
}
|
}
|
||||||
if (at != bt){
|
if(at != bt)
|
||||||
|
{
|
||||||
result = 0;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal U64
|
internal U64
|
||||||
|
|||||||
Reference in New Issue
Block a user