[ruby/did_you_mean] Do not use #inspect to avoid unexpected performance degradation

closes https://github.com/ruby/did_you_mean/pull/100

https://github.com/ruby/did_you_mean/commit/bd11eefd6c
This commit is contained in:
Yuki Nishijima 2024-03-19 10:25:55 +09:00 committed by git
parent 3f5f04afa7
commit 6c1e8029d0
2 changed files with 18 additions and 2 deletions

View File

@ -14,7 +14,15 @@ module DidYouMean
private
def exact_matches
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map(&:inspect)
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) }
end
def format_object(symbol_or_object)
if symbol_or_object.is_a?(Symbol)
":#{symbol_or_object}"
else
symbol_or_object.to_s
end
end
end
end

View File

@ -14,7 +14,15 @@ module DidYouMean
private
def exact_matches
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map(&:inspect)
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) }
end
def format_object(symbol_or_object)
if symbol_or_object.is_a?(Symbol)
":#{symbol_or_object}"
else
symbol_or_object.to_s
end
end
end
end