diff options
| author | Ellen Marie Dash <me@duckie.co> | 2024-09-28 14:28:53 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-10-23 20:03:14 +0000 |
| commit | ff749d9956ed8fca9b1b2e419a574dd525b87167 (patch) | |
| tree | c2515e040538897eb79b65be78a40e4f70d4e183 | |
| parent | fe66eee1a01eea711baa1d750424ed6624e38b37 (diff) | |
[rubygems/rubygems] Optimize when suggest_gems_from_name finds an exact match.
https://github.com/rubygems/rubygems/commit/6c67298584
| -rw-r--r-- | lib/rubygems/spec_fetcher.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index 946e327ec8..b8ed9f219d 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -187,15 +187,18 @@ class Gem::SpecFetcher # If the gem doesn't support the current platform, bail early. next unless n.match_platform? - distance = levenshtein_distance gem_name, n.name.downcase.tr("_-", "") - - # Edit distance is greater than the maximum we allow, so skip this result. - next if distance >= max + # The candidate name, normalized the same as gem_name. + normalized_name = n.name.downcase.tr("_-", "") # If we found an exact match (after stripping underscores and hyphens), # that's our most likely candidate. # Return it immediately, and skip the rest of the loop. - return [n.name] if distance == 0 + return [n.name] if normalized_name == gem_name + + distance = levenshtein_distance gem_name, normalized_name + + # Skip current candidate, if the edit distance is greater than allowed. + next if distance >= max # If all else fails, return the name and the calculated distance. [n.name, distance] |
