aboutsummaryrefslogtreecommitdiff
path: root/builtins/table.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/table.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/table.c')
-rw-r--r--builtins/table.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/builtins/table.c b/builtins/table.c
index 22797775..b1d82c3c 100644
--- a/builtins/table.c
+++ b/builtins/table.c
@@ -395,6 +395,8 @@ public table_t Table$sorted(table_t t, const TypeInfo *type)
public bool Table$equal(const table_t *x, const table_t *y, const TypeInfo *type)
{
+ if (x == y) return true;
+
assert(type->tag == TableInfo);
if (Table$length(*x) != Table$length(*y))
return false;
@@ -407,6 +409,8 @@ public bool Table$equal(const table_t *x, const table_t *y, const TypeInfo *type
public int32_t Table$compare(const table_t *x, const table_t *y, const TypeInfo *type)
{
+ if (x == y) return 0;
+
assert(type->tag == TableInfo);
auto table = type->TableInfo;
if (x->entries.length == 0)