aboutsummaryrefslogtreecommitdiff
path: root/builtins/range.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-05 10:31:35 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-05 10:31:35 -0400
commit8d41b2b1fbe3edc870b9456b991446aaa8b3dddd (patch)
tree7c8be033455da86d6be0f6ec9f17451fe41494ed /builtins/range.c
parentd3c4f613ac9bc711858bc1c74c8232a7d86666dc (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/range.c')
-rw-r--r--builtins/range.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/builtins/range.c b/builtins/range.c
index d170e6b7..068d8cea 100644
--- a/builtins/range.c
+++ b/builtins/range.c
@@ -18,6 +18,7 @@
static int32_t Range$compare(const Range_t *x, const Range_t *y, const TypeInfo *type)
{
(void)type;
+ if (x == y) return 0;
int32_t diff = Int$compare(&x->first, &y->first, &$Int);
if (diff != 0) return diff;
diff = Int$compare(&x->last, &y->last, &$Int);
@@ -28,6 +29,7 @@ static int32_t Range$compare(const Range_t *x, const Range_t *y, const TypeInfo
static bool Range$equal(const Range_t *x, const Range_t *y, const TypeInfo *type)
{
(void)type;
+ if (x == y) return true;
return Int$equal(&x->first, &y->first, &$Int) && Int$equal(&x->last, &y->last, &$Int) && Int$equal(&x->step, &y->step, &$Int);
}