diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-05 10:31:35 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-05 10:31:35 -0400 |
| commit | 8d41b2b1fbe3edc870b9456b991446aaa8b3dddd (patch) | |
| tree | 7c8be033455da86d6be0f6ec9f17451fe41494ed /builtins/text.c | |
| parent | d3c4f613ac9bc711858bc1c74c8232a7d86666dc (diff) | |
Do the extremely obvious optimization of checking if two pieces of data
are at the same location before bothering to compare them
Diffstat (limited to 'builtins/text.c')
| -rw-r--r-- | builtins/text.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/builtins/text.c b/builtins/text.c index 1871fb1c..5e87027b 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -864,6 +864,8 @@ int32_t get_grapheme(Text_t text, int64_t index) public int32_t Text$compare(const Text_t *a, const Text_t *b) { + if (a == b) return 0; + int64_t len = MAX(a->length, b->length); iteration_state_t a_state = {0, 0}, b_state = {0, 0}; for (int64_t i = 0; i < len; i++) { @@ -897,6 +899,8 @@ public int32_t Text$compare(const Text_t *a, const Text_t *b) public bool Text$equal(const Text_t *a, const Text_t *b) { + if (a == b) return true; + if (a->length != b->length || (a->hash != 0 && b->hash != 0 && a->hash != b->hash)) return false; int64_t len = a->length; |
