Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible optimization of byterun/str.c #4126

Closed
vicuna opened this issue Sep 30, 2006 · 1 comment
Closed

possible optimization of byterun/str.c #4126

vicuna opened this issue Sep 30, 2006 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Sep 30, 2006

Original bug ID: 4126
Reporter: MIchaelWohlwend
Status: closed (set by @xavierleroy on 2006-10-09T13:08:12Z)
Resolution: not a bug
Priority: normal
Severity: tweak
Version: 3.09.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: MIchaelWohlwend

Bug description

while looking over the code I realized that in byterun/str.c the function caml_string_compare could be a little optimized, by moving the memcmp after the comparing of the length, the comparing of len1 and len2 for memcmp ins't neccesary anymore.
Maybe string-compares go even faster than now :-)

Here is my patch:

diff -u strorg.c str.c
--- strorg.c 2005-09-22 16:21:50.000000000 +0200
+++ str.c 2006-09-30 18:24:43.923951216 +0200
@@ -88,11 +88,11 @@

len1 = caml_string_length(s1);
len2 = caml_string_length(s2);

  • res = memcmp(String_val(s1), String_val(s2), len1 <= len2 ? len1 : len2);
  • if (res < 0) return Val_int(-1);
  • if (res > 0) return Val_int(1);
    if (len1 < len2) return Val_int(-1);
    if (len1 > len2) return Val_int(1);
  • res = memcmp(String_val(s1), String_val(s2), len1);
  • if (res < 0) return Val_int(-1);
  • if (res > 0) return Val_int(1);
    return Val_int(0);
    }
@vicuna
Copy link
Author

vicuna commented Oct 9, 2006

Comment author: @xavierleroy

If I understand correctly the proposed patch, it would result in "zzz"
being less than "aaaa", which is not what we want (i.e. lexicographic
ordering).

@vicuna vicuna closed this as completed Oct 9, 2006
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant