From fc8e446d5da1887044c86ed07e8cf2eee6cf2cfd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 24 Jan 2016 09:41:09 +0000 Subject: String#split with a single-byte instead of regexp This reduces memory usage as a Regexp object is hundreds of bytes and a single-byte string object is only 40 bytes that is deduped within the VM. --- lib/dtas/format.rb | 2 +- lib/dtas/partstats.rb | 2 +- lib/dtas/player/client_handler.rb | 4 ++-- lib/dtas/source/mp3gain.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/dtas/format.rb b/lib/dtas/format.rb index 001a444..f378f8e 100644 --- a/lib/dtas/format.rb +++ b/lib/dtas/format.rb @@ -164,7 +164,7 @@ class DTAS::Format # :nodoc: end # deal with HH:MM:SS - t = time.split(/:/) + t = time.split(':') raise ArgumentError, "Bad time format: #{hhmmss}" if t.size > 3 mult = 1 diff --git a/lib/dtas/partstats.rb b/lib/dtas/partstats.rb index cd37e0a..9714ebe 100644 --- a/lib/dtas/partstats.rb +++ b/lib/dtas/partstats.rb @@ -160,7 +160,7 @@ becomes: def parse_stats(stats, trim_part, buf) trim_row = [ trim_part ] - buf.split(/\n/).each do |line| + buf.split("\n").each do |line| do_map = true case line when /\A(\S+ \S+ dB)\s/, /\A(Crest factor)\s+-\s/ diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index 7ce9839..a6f5dba 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -422,7 +422,7 @@ module DTAS::Player::ClientHandler # :nodoc: def dpc_format(io, msg) new_fmt = @format.dup msg.each do |kv| - k, v = kv.split(/=/, 2) + k, v = kv.split('=', 2) case k when "type" new_fmt.valid_type?(v) or return io.emit("ERR invalid file type") @@ -497,7 +497,7 @@ module DTAS::Player::ClientHandler # :nodoc: before = src.to_state_hash.inspect sd = src.source_defaults msg.each do |kv| - k, v = kv.split(/=/, 2) + k, v = kv.split('=', 2) case k when "command" src.command = v.empty? ? sd[k] : v diff --git a/lib/dtas/source/mp3gain.rb b/lib/dtas/source/mp3gain.rb index e33b48a..47b24c6 100644 --- a/lib/dtas/source/mp3gain.rb +++ b/lib/dtas/source/mp3gain.rb @@ -16,7 +16,7 @@ module DTAS::Source::Mp3gain # :nodoc: case @infile when String @infile =~ /\.mp[g23]\z/in or return - qx(%W(mp3gain -s c #@infile)).split(/\n/).each do |line| + qx(%W(mp3gain -s c #@infile)).split("\n").each do |line| case line when /^Recommended "(Track|Album)" dB change:\s*(\S+)/ tmp["REPLAYGAIN_#{$1.upcase}_GAIN"] = $2 -- cgit v1.2.3-24-ge0c7