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

Memory allocations #184

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/deface/override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def digest
#
def self.digest(details)
overrides = self.find(details)
to_hash = overrides.inject('') { |digest, override| digest << override.digest }
to_hash = overrides.inject(''.freeze) { |digest, override| digest << override.digest }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to become a +=.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean overrides.inject('') { |digest, override| digest += override.digest } ?

Uhm maybe also overrides.map(&:digest).join?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProGM I mean:

overrides.inject(''.freeze) { |digest, override| digest += override.digest }

<< will fail on a frozen string because it attempts to mutate the object, so you need to create a new string every time. I'm not sure if that will negate the performance benefits of using .freeze though.

Deface::Digest.hexdigest(to_hash)
end

Expand Down
7 changes: 5 additions & 2 deletions lib/deface/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ def find(details)
virtual_path = details[:virtual_path]
return [] if virtual_path.nil?

[/^\//, /\.\w+\z/].each { |regex| virtual_path.gsub!(regex, '') }
[/^\//, /\.\w+\z/].each { |regex| virtual_path.gsub!(regex, ''.freeze) }

result = []
result << self.all[virtual_path.to_sym].try(:values)

result = result.flatten
result.compact!

result.flatten.compact.sort_by &:sequence
result.sort_by &:sequence
end

# finds all overrides that are using a template / parital as there source
Expand Down