Skip to content

Commit

Permalink
Do not use #inspect to avoid unexpected performance degradation
Browse files Browse the repository at this point in the history
closes #100
  • Loading branch information
yuki24 committed Mar 19, 2024
1 parent 9756261 commit bd11eef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/did_you_mean/spell_checkers/key_error_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ def corrections
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
10 changes: 9 additions & 1 deletion lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ def corrections
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

0 comments on commit bd11eef

Please sign in to comment.