-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Use Erlang's implementation of jaro distance, fix bugs #13369
Conversation
lib/elixir/lib/string.ex
Outdated
# TODO: Remove me when we require Erlang/OTP 27+ | ||
@jaro_module if :erlang.system_info(:otp_release) >= [?2, ?7], do: :string, else: :elixir_utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure: is it enough to check the OTP version at compile time, or is there another preferred way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just always call the one in elixir_utils for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
@@ -999,6 +999,7 @@ defmodule StringTest do | |||
assert String.jaro_distance("jon", "john") == 0.9166666666666666 | |||
assert String.jaro_distance("jon", "jan") == 0.7777777777777777 | |||
assert String.jaro_distance("семена", "стремя") == 0.6666666666666666 | |||
assert String.jaro_distance("Sunday", "Saturday") == 0.7194444444444444 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the example mentioned here
def jaro_distance(string, string) when is_binary(string), do: 1.0 | ||
def jaro_distance(_string, ""), do: 0.0 | ||
def jaro_distance("", _string), do: 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt we could keep these optimizations since they weren't in the Erlang version, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to keep them, yeah. :)
@josevalim should I backport this one since it's a bug? Or not because of the vendored thing? |
Let's not backport this one, it seems a bit larger for a patch release and the bug has been there for several versions anyway. |
Close #13349
Copies the implementation of erlang/otp#7879