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

Object allocation during parsing method name #221

Merged
merged 1 commit into from Sep 2, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## Next Release

* Your contribution here.
* [#221](https://github.com/intridea/hashie/pull/221): Reduce amount of allocated objects on calls with suffixes in Hashie::Mash - [@kubum](https://github.com/kubum).

## 3.3.1 (8/26/2014)

Expand Down
4 changes: 2 additions & 2 deletions lib/hashie/mash.rb
Expand Up @@ -58,6 +58,7 @@ class Mash < Hash
include Hashie::Extensions::PrettyInspect

ALLOWED_SUFFIXES = %w(? ! = _)
SUFFIXES_PARSER = /(.*?)([#{ALLOWED_SUFFIXES.join}]?)$/

def self.load(path, options = {})
@_mashes ||= new do |h, file_path|
Expand Down Expand Up @@ -251,8 +252,7 @@ def method_missing(method_name, *args, &blk)
protected

def method_suffix(method_name)
suffixes_regex = ALLOWED_SUFFIXES.join
match = method_name.to_s.match(/(.*?)([#{suffixes_regex}]?)$/)
match = method_name.to_s.match(SUFFIXES_PARSER)
[match[1], match[2]]
end

Expand Down