aboutsummaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-01-18 16:17:02 +0000
committergingerBill <bill@gingerbill.org>2023-01-18 16:17:02 +0000
commit7f3795a231f96690a7668a61ce71420025306970 (patch)
treea3380fa431a653c6a175cd531b80a92f9b543166 /src/string.cpp
parenteb1d00ced6e27453b52f4420766cca8886898d01 (diff)
Improve `odin doc` string printing (Fixes #2246)
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp49
1 files changed, 15 insertions, 34 deletions
diff --git a/src/string.cpp b/src/string.cpp
index a2254d100..af6c437e1 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -106,42 +106,23 @@ gb_internal void string_to_lower(String *s) {
}
}
-gb_internal int string_compare(String const &x, String const &y) {
- if (x.len != y.len || x.text != y.text) {
- isize n, fast, offset, curr_block;
- isize *la, *lb;
- isize pos;
-
- n = gb_min(x.len, y.len);
-
- fast = n/gb_size_of(isize) + 1;
- offset = (fast-1)*gb_size_of(isize);
- curr_block = 0;
- if (n <= gb_size_of(isize)) {
- fast = 0;
- }
-
- la = cast(isize *)x.text;
- lb = cast(isize *)y.text;
-
- for (; curr_block < fast; curr_block++) {
- if (la[curr_block] ^ lb[curr_block]) {
- for (pos = curr_block*gb_size_of(isize); pos < n; pos++) {
- if (x[pos] ^ y[pos]) {
- return cast(int)x[pos] - cast(int)y[pos];
- }
- }
- }
- }
+gb_internal int string_compare(String const &a, String const &b) {
+ if (a.text == b.text) {
+ return 0;
+ }
+ if (a.text == nullptr) {
+ return -1;
+ }
+ if (b.text == nullptr) {
+ return +1;
+ }
- for (; offset < n; offset++) {
- if (x[offset] ^ y[offset]) {
- return cast(int)x[offset] - cast(int)y[offset];
- }
- }
- return cast(int)(x.len - y.len);
+ uintptr n = gb_min(a.len, b.len);
+ int res = memcmp(a.text, b.text, n);
+ if (res == 0) {
+ res = cast(int)(a.len - b.len);
}
- return 0;
+ return res;
}
gb_internal isize string_index_byte(String const &s, u8 x) {