diff --git a/CHANGELOG.md b/CHANGELOG.md index 32666185..108ed5db 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index 182fddb9..b7ad40b4 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -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| @@ -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