From f4c2ac4825f99ec4af529d65ae98abfaf034fb0f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Mar 2017 04:08:23 +0000 Subject: deduplicate strings using String#-@ (uminus) in Ruby 2.5+ This is faster than relying on eval() for older Rubies. https://bugs.ruby-lang.org/issues/13077 Ruby 2.5 is targetted for release in December 2017. --- lib/dtas/mlib.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/dtas/mlib.rb') diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb index dbd46da..0945153 100644 --- a/lib/dtas/mlib.rb +++ b/lib/dtas/mlib.rb @@ -190,7 +190,9 @@ class DTAS::Mlib # :nodoc: tag_id = tag_map[x] and tag_map["#{x}number"] = tag_id end @tag_rmap = tag_map.invert.freeze - tag_map.merge!(Hash[*(tag_map.map { |k,v| [k.upcase.freeze, v] }.flatten!)]) + tag_map.merge!(Hash[*(tag_map.map { |k,v| + [DTAS.dedupe_str(k.upcase), v] + }.flatten!)]) @tag_map = tag_map.freeze end @@ -400,7 +402,7 @@ class DTAS::Mlib # :nodoc: return '/' if base == '' # root_node parent_id = node[:parent_id] base += '/' unless node[:tlen] >= 0 - ppath = cache[parent_id] and return "#{ppath}/#{base}" + ppath = cache[parent_id] and return DTAS.dedupe_str("#{ppath}/#{base}") parts = [] begin node = @db[:nodes][id: node[:parent_id]] @@ -408,9 +410,9 @@ class DTAS::Mlib # :nodoc: parts.unshift node[:name] end while true parts.unshift('') - cache[parent_id] = parts.join('/') + cache[parent_id] = DTAS.dedupe_str(parts.join('/')) parts << base - parts.join('/').freeze + DTAS.dedupe_str(parts.join('/')) end def emit_recurse(node, cache, cb) -- cgit v1.2.3-24-ge0c7