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/functions.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/functions.c')
| -rw-r--r-- | builtins/functions.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/builtins/functions.c b/builtins/functions.c index b6132494..c11dd7e6 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -122,6 +122,8 @@ public uint64_t generic_hash(const void *obj, const TypeInfo *type) public int32_t generic_compare(const void *x, const void *y, const TypeInfo *type) { + if (x == y) return 0; + switch (type->tag) { case PointerInfo: case FunctionInfo: return Pointer$compare(x, y, type); case TextInfo: return Text$compare(x, y); @@ -141,6 +143,8 @@ public int32_t generic_compare(const void *x, const void *y, const TypeInfo *typ public bool generic_equal(const void *x, const void *y, const TypeInfo *type) { + if (x == y) return true; + switch (type->tag) { case PointerInfo: case FunctionInfo: return Pointer$equal(x, y, type); case TextInfo: return Text$equal(x, y); |
