diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-09-09 23:33:54 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-09-09 23:33:54 +0100 |
| commit | 6979678ff947cecc8e6e0d0e8ceea7e0304d3f4e (patch) | |
| tree | 774b9480272eba57e1a09011107cc136b43dde65 /src/string.cpp | |
| parent | 1ca752ce049b934df5d03af2f06265e219f5f402 (diff) | |
Begin reording of struct members by default.
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp index 8b5e3aa4b..743d5dcd4 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -43,6 +43,46 @@ gb_inline b32 are_strings_equal_ignore_case(String a, String b) { return false; } +GB_COMPARE_PROC(string_cmp) { + String x = *cast(String *)a; + String y = *cast(String *)b; + + if (x.len == y.len && + x.text == y.text) { + return 0; + } + + isize n = gb_min(x.len, y.len); + + isize fast = n/gb_size_of(isize) + 1; + isize offset = (fast-1)*gb_size_of(isize); + isize curr_block = 0; + if (n <= gb_size_of(isize)) { + fast = 0; + } + + isize *la = cast(isize *)x.text; + isize *lb = cast(isize *)y.text; + + for (; curr_block < fast; curr_block++) { + if ((la[curr_block] ^ lb[curr_block]) != 0) { + for (isize pos = curr_block*gb_size_of(isize); pos < n; pos++) { + if ((x.text[pos] ^ y.text[pos]) != 0) { + return cast(int)x.text[pos] - cast(int)y.text[pos]; + } + } + } + } + + for (; offset < n; offset++) { + if ((x.text[offset] ^ y.text[offset]) != 0) { + return cast(int)x.text[offset] - cast(int)y.text[offset]; + } + } + + return 0; +} + gb_inline isize string_extension_position(String str) { isize dot_pos = -1; |