aboutsummaryrefslogtreecommitdiff
path: root/builtins/c_string.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/c_string.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/c_string.c')
-rw-r--r--builtins/c_string.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/builtins/c_string.c b/builtins/c_string.c
index bd35b549..47ea4858 100644
--- a/builtins/c_string.c
+++ b/builtins/c_string.c
@@ -21,10 +21,14 @@ public Text_t CString$as_text(const void *c_string, bool colorize, const TypeInf
return Text$concat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("), Text$quoted(text, colorize), Text(")"));
}
-public int CString$compare(const char **x, const char **y)
+public int32_t CString$compare(const char **x, const char **y)
{
+ if (x == y)
+ return 0;
+
if (!*x != !*y)
return (!*y) - (!*x);
+
return strcmp(*x, *y);
}