From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id F04271F852 for ; Thu, 20 Jan 2022 22:59:41 +0000 (UTC) Received: from localhost ([::1]:58410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAgP6-0002Zu-PF for e@80x24.org; Thu, 20 Jan 2022 17:59:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAcGj-0003Ul-Ga for dtas-all@nongnu.org; Thu, 20 Jan 2022 13:34:45 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:47372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAcGe-0004mJ-3p for dtas-all@nongnu.org; Thu, 20 Jan 2022 13:34:43 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5F5EB1FA00 for ; Thu, 20 Jan 2022 18:34:20 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH 2/4] get rid of DTAS.dedupe_str wrapper Date: Thu, 20 Jan 2022 18:34:17 +0000 Message-Id: <20220120183419.2214-3-e@80x24.org> In-Reply-To: <20220120183419.2214-1-e@80x24.org> References: <20220120183419.2214-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" Ruby 2.3+ supports String#@-, though it did not deduplicate strings. But 2.5 is already old at this point and most users can be expected to have it. This gives some memory regressions for Ruby <= 2.4 users, but cuts down on the code we maintain and reduces bytecode overhead for 2.5+ users. --- lib/dtas.rb | 13 ------------- lib/dtas/fadefx.rb | 4 ++-- lib/dtas/mlib.rb | 12 +++++------- lib/dtas/partstats.rb | 2 +- lib/dtas/player.rb | 4 ++-- lib/dtas/player/client_handler.rb | 6 +++--- lib/dtas/rg_state.rb | 4 ++-- lib/dtas/source/av_ff_common.rb | 6 +++--- lib/dtas/source/sox.rb | 6 +++--- lib/dtas/watchable/fiddle_ino.rb | 4 ++-- 10 files changed, 23 insertions(+), 38 deletions(-) diff --git a/lib/dtas.rb b/lib/dtas.rb index eb8f49d..477a176 100644 --- a/lib/dtas.rb +++ b/lib/dtas.rb @@ -25,19 +25,6 @@ def self.libc Fiddle.dlopen(nil) end end - - # String#-@ will deduplicate strings when Ruby 2.5 is released (Dec 2017) - # https://bugs.ruby-lang.org/issues/13077 - if RUBY_VERSION.to_f >= 2.5 - def self.dedupe_str(str) - -str - end - else - # Ruby 2.1 - 2.4, noop for older Rubies - def self.dedupe_str(str) - eval "#{str.inspect}.freeze" - end - end # :startdoc: end diff --git a/lib/dtas/fadefx.rb b/lib/dtas/fadefx.rb index 7bccff8..0ec108c 100644 --- a/lib/dtas/fadefx.rb +++ b/lib/dtas/fadefx.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true require_relative '../dtas' @@ -95,7 +95,7 @@ def fade_in_next_fx(format, tbeg, tlen) def parse!(str) return nil if str.empty? type = "t" - str.sub!(/\A([a-z])/, "") and type = DTAS.dedupe_str($1) + str.sub!(/\A([a-z])/, "") and type = -$1 F.new(type, parse_time(str)) end end diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb index eb7554a..f99ed6a 100644 --- a/lib/dtas/mlib.rb +++ b/lib/dtas/mlib.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -# Copyright (C) 2015-2021 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true # @@ -201,9 +201,7 @@ def load_tags 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| - [DTAS.dedupe_str(k.upcase), v] - }.flatten!)]) + tag_map.merge!(Hash[*(tag_map.map { |k,v| [-(k.upcase), v] }.flatten!)]) @tag_map = tag_map.freeze end @@ -421,7 +419,7 @@ def path_of(node, cache) return '/' if base == '' # root_node parent_id = node[:parent_id] base += '/' unless node[:tlen] >= 0 - ppath = cache[parent_id] and return DTAS.dedupe_str("#{ppath}/#{base}") + ppath = cache[parent_id] and return -"#{ppath}/#{base}" parts = [] begin node = @db[:nodes][id: node[:parent_id]] @@ -429,9 +427,9 @@ def path_of(node, cache) parts.unshift node[:name] end while true parts.unshift('') - cache[parent_id] = DTAS.dedupe_str(parts.join('/')) + cache[parent_id] = -(parts.join('/')) parts << base - DTAS.dedupe_str(parts.join('/')) + -(parts.join('/')) end def emit_recurse(node, cache, cb) diff --git a/lib/dtas/partstats.rb b/lib/dtas/partstats.rb index 8e9ee95..061ff50 100644 --- a/lib/dtas/partstats.rb +++ b/lib/dtas/partstats.rb @@ -171,7 +171,7 @@ def parse_stats(stats, trim_part, buf) else next end - key = DTAS.dedupe_str($1) + key = -$1 key_idx = @key_idx[key] parts = line.split(/\s+/) nshift.times { parts.shift } # remove stuff we don't need diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb index b39a2e7..ff7440f 100644 --- a/lib/dtas/player.rb +++ b/lib/dtas/player.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true require 'yaml' @@ -168,7 +168,7 @@ def self.load(hash) if sinks = hash["sinks"] sinks.each do |sink_hsh| - sink_hsh['name'] = DTAS.dedupe_str(sink_hsh['name']) + sink_hsh['name'] = -sink_hsh['name'] sink = DTAS::Sink.load(sink_hsh) sink.env = to_omap(sink.env) @sinks[sink.name] = sink diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index cf5442d..2914fe7 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true require_relative '../xs' @@ -135,7 +135,7 @@ def dpc_sink(io, msg) # or variable names. sink.valid_name?(name) or return io.emit("ERR sink name invalid") - sink.name = DTAS.dedupe_str(name) + sink.name = -name active_before = sink.active before = __sink_snapshot(sink) @@ -144,7 +144,7 @@ def dpc_sink(io, msg) k, v = kv.split('=', 2) case k when %r{\Aenv\.([^=]+)\z} - sink.env[DTAS.dedupe_str($1)] = v + sink.env[$1] = v when %r{\Aenv#([^=]+)\z} v == nil or return io.emit("ERR unset env has no value") sink.env.delete($1) diff --git a/lib/dtas/rg_state.rb b/lib/dtas/rg_state.rb index d463bd8..9a44835 100644 --- a/lib/dtas/rg_state.rb +++ b/lib/dtas/rg_state.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true # @@ -72,7 +72,7 @@ def to_sox_gain(val) when 1 then return 'gain 192' else val.abs <= 0.00000001 and return - DTAS.dedupe_str(sprintf('gain %0.8f', val)) + -sprintf('gain %0.8f', val) end end diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb index 6f92762..5299fdb 100644 --- a/lib/dtas/source/av_ff_common.rb +++ b/lib/dtas/source/av_ff_common.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true require_relative '../../dtas' @@ -110,7 +110,7 @@ def av_ff_ok? f =~ /^duration=([\d\.]+)\s*$/nm and @duration = $1.to_f # TODO: multi-line/multi-value/repeated tags f.gsub!(/^TAG:([^=]+)=(.*)$/ni) { |_| - @comments[DTAS.dedupe_str($1.upcase)] = DTAS.dedupe_str($2) + @comments[$1.upcase] = -($2) } end @@ -118,7 +118,7 @@ def av_ff_ok? s.scan(%r{^\[format\.tags\]\n(.*?)\n\n}m) do |_| f = $1.dup f.gsub!(/^([^=]+)=(.*)$/ni) { |_| - @comments[DTAS.dedupe_str($1.upcase)] = DTAS.dedupe_str($2) + @comments[$1.upcase] = -$2 } end s.scan(%r{^\[format\]\n(.*?)\n\n}m) do |_| diff --git a/lib/dtas/source/sox.rb b/lib/dtas/source/sox.rb index 3a7fe7d..e38e23c 100644 --- a/lib/dtas/source/sox.rb +++ b/lib/dtas/source/sox.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true # encoding: binary @@ -56,14 +56,14 @@ def mcache_lookup(infile) key = nil $1.split(/\n/n).each do |line| if line.sub!(/^([^=]+)=/ni, '') - key = DTAS.dedupe_str(DTAS.try_enc($1.upcase, enc)) + key = DTAS.try_enc($1.upcase, enc) end (comments[key] ||= ''.b) << "#{line}\n" unless line.empty? end comments.each do |k,v| v.chomp! DTAS.try_enc(v, enc) - comments[k] = DTAS.dedupe_str(v) + comments[k] = v end end dst diff --git a/lib/dtas/watchable/fiddle_ino.rb b/lib/dtas/watchable/fiddle_ino.rb index e85fea1..b24bbf6 100644 --- a/lib/dtas/watchable/fiddle_ino.rb +++ b/lib/dtas/watchable/fiddle_ino.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true require 'fiddle' @@ -53,7 +53,7 @@ def take(nonblock) # :nodoc: name.size == len or raise "short name #{name.inspect} != #{len}" name.sub!(/\0+\z/, '') or raise "missing: `\\0', inotify_event.name=#{name.inspect}" - name = DTAS.dedupe_str(name) + name = -name end ie = InotifyEvent.new(wd, mask, cookie, len, name) if event