From 705a7eb707f9d4ac5ccd1474f9bb61730f9f12e7 Mon Sep 17 00:00:00 2001 From: Andrey Fadeyev Date: Mon, 1 Sep 2014 22:09:44 +0100 Subject: suffix parser pattern is constant - we shouldn't compile it every time for suffix recognition --- CHANGELOG.md | 1 + lib/hashie/mash.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3266618..108ed5d 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 182fddb..b7ad40b 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -58,6 +58,7 @@ module Hashie 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 @@ module Hashie 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 -- cgit v1.2.1