Skip to content

Commit

Permalink
Freeze all the strings!
Browse files Browse the repository at this point in the history
Reduces runtime allocation by freezing string literals by default.

We could also remove a ton of manual `.freeze` calls, however the ruby supported version is 2.2 and the magic comment only targets 2.3+.
  • Loading branch information
schneems committed Sep 17, 2018
1 parent f7e1e58 commit 88e51fb
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/puma/binder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'uri'
require 'socket'

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'optparse'
require 'uri'

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class IO
# We need to use this for a jruby work around on both 1.8 and 1.9.
# So this either creates the constant (on 1.8), or harmlessly
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/cluster.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/runner'
require 'puma/util'
require 'puma/plugin'
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/commonlogger.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
# Rack::CommonLogger forwards every request to the given +app+, and
# logs a line in the
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/rack/builder'
require 'puma/plugin'
require 'puma/const'
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/const.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#encoding: utf-8
# frozen_string_literal: true

module Puma
class UnsupportedOption < RuntimeError
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/control_cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'optparse'
require 'puma/state_file'
require 'puma/const'
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/convenient.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/launcher'
require 'puma/configuration'

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/daemon_ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Process

# This overrides the default version because it is broken if it
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/delegation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
module Delegation
def forward(what, who)
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/detect.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
IS_JRUBY = defined?(JRUBY_VERSION)

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
# The methods that are available for use inside the config file.
# These same methods are used in Puma cli and the rack handler
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/events.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/const'
require "puma/null_io"
require 'stringio'
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/io_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/detect'

if Puma.jruby?
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/java_io_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'java'

# Conservative native JRuby/Java implementation of IOBuffer
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/jruby_restart.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'ffi'

module Puma
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/launcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/events'
require 'puma/detect'

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/minissl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'io/wait'
rescue LoadError
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/null_io.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
# Provides an IO-like object that always appears to contain no data.
# Used as the value for rack.input when the request has no body.
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
class UnknownPlugin < RuntimeError; end

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/reactor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/util'
require 'puma/minissl'

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/server'
require 'puma/const'

Expand Down
2 changes: 2 additions & 0 deletions lib/puma/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'stringio'

require 'puma/thread_pool'
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/single.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puma/runner'
require 'puma/detect'
require 'puma/plugin'
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/state_file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'yaml'

module Puma
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/tcp_logger.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Puma
class TCPLogger
def initialize(logger, app, quiet=false)
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/thread_pool.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'thread'

module Puma
Expand Down
1 change: 1 addition & 0 deletions lib/puma/util.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i }

if major == 1 && minor == 9 && patch == 3 && RUBY_PATCHLEVEL < 125
Expand Down

0 comments on commit 88e51fb

Please sign in to comment.