diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2007-01-30 09:52:08 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2007-01-30 09:52:08 +0000 |
commit | 1baa43a304038137613ca7ab7d29886a69582e43 (patch) | |
tree | 1bf1de92c5b34fb75661da009353ecc5cee69590 | |
parent | 6ce858f4a8cff5682a88f2978eb5a7618e48def6 (diff) |
Added shortcut if == to caml_string_compare and caml_string_equal
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7819 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | byterun/str.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/byterun/str.c b/byterun/str.c index 79e4ef81b..380e2eb5a 100644 --- a/byterun/str.c +++ b/byterun/str.c @@ -67,9 +67,12 @@ CAMLprim value caml_string_set(value str, value index, value newval) CAMLprim value caml_string_equal(value s1, value s2) { - mlsize_t sz1 = Wosize_val(s1); - mlsize_t sz2 = Wosize_val(s2); + mlsize_t sz1, sz2; value * p1, * p2; + + if (s1 == s2) return Val_true; + sz1 = Wosize_val(s1); + sz2 = Wosize_val(s2); if (sz1 != sz2) return Val_false; for(p1 = Op_val(s1), p2 = Op_val(s2); sz1 > 0; sz1--, p1++, p2++) if (*p1 != *p2) return Val_false; @@ -86,6 +89,7 @@ CAMLprim value caml_string_compare(value s1, value s2) mlsize_t len1, len2; int res; + if (s1 == s2) return Val_int(0); len1 = caml_string_length(s1); len2 = caml_string_length(s2); res = memcmp(String_val(s1), String_val(s2), len1 <= len2 ? len1 : len2); |