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

Optimize both allocated and retained memory usage #17

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ GEM
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-21
x86_64-darwin-23
arm64-darwin
x86_64-darwin
x86_64-linux

DEPENDENCIES
Expand Down
2 changes: 1 addition & 1 deletion lib/zxcvbn/frequency_lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.file_enumerator(filename)
f.each_line do |line|
next if line.nil?

main_enum << line.strip!
main_enum << line.strip!.freeze
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/zxcvbn/matching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.build_ranked_dict(ordered_list)
end

RANKED_DICTIONARIES_MAX_WORD_SIZE = RANKED_DICTIONARIES.transform_values do |word_scores|
word_scores.keys.max_by(&:size).size
word_scores.each_key.max_by(&:size)&.size || 0
end

GRAPHS = {
Expand Down Expand Up @@ -159,7 +159,7 @@ def self.check_dictionary(matches, password, dictionary_name, ranked_dict)
len = password.length
password_lower = password.downcase
longest_word_size = RANKED_DICTIONARIES_MAX_WORD_SIZE.fetch(dictionary_name) do
ranked_dict.keys.max_by(&:size)&.size || 0
ranked_dict.each_key.max_by(&:size)&.size || 0
end
search_width = [longest_word_size, len].min
(0...len).each do |i|
Expand Down
6 changes: 3 additions & 3 deletions lib/zxcvbn/scoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.calc_average_degree(graph)
graph.each_value do |neighbors|
average += neighbors.count { |n| n }.to_f
end
average /= graph.keys.size.to_f
average /= graph.size.to_f
average
end

Expand Down Expand Up @@ -324,8 +324,8 @@ def self.date_guesses(match)
# slightly different for keypad/mac keypad, but close enough
KEYPAD_AVERAGE_DEGREE = calc_average_degree(ADJACENCY_GRAPHS["keypad"]).freeze

KEYBOARD_STARTING_POSITIONS = ADJACENCY_GRAPHS["qwerty"].keys.size
KEYPAD_STARTING_POSITIONS = ADJACENCY_GRAPHS["keypad"].keys.size
KEYBOARD_STARTING_POSITIONS = ADJACENCY_GRAPHS["qwerty"].size
KEYPAD_STARTING_POSITIONS = ADJACENCY_GRAPHS["keypad"].size

def self.spatial_guesses(match)
if ["qwerty", "dvorak"].include?(match["graph"])
Expand Down