aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-05-08 22:04:11 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-05-08 22:04:11 +0900
commit330d1d657fbc9c06c0e3304d8cb4ab6a2b4e948c (patch)
tree26a694f7f27646dfd722948d7bfd0a682fb75f7b
parentfed5ea65bc7ac477379e9feda82f0e4d00a00e29 (diff)
downloadplum-330d1d657fbc9c06c0e3304d8cb4ab6a2b4e948c.tar.gz
style: prefer "".b over String.new
String.new requires a constant search and method search, while "".b requires only a method search.
-rw-r--r--examples/client/twitter.rb2
-rw-r--r--examples/non_tls_server.rb2
-rw-r--r--examples/static_server.rb2
-rw-r--r--lib/plum/client/legacy_client_session.rb2
-rw-r--r--lib/plum/connection.rb2
-rw-r--r--lib/plum/frame/goaway.rb2
-rw-r--r--lib/plum/frame/push_promise.rb2
-rw-r--r--lib/plum/frame/rst_stream.rb2
-rw-r--r--lib/plum/frame/settings.rb2
-rw-r--r--lib/plum/frame/window_update.rb2
-rw-r--r--lib/plum/hpack/huffman.rb4
-rw-r--r--lib/plum/rack/session.rb2
-rw-r--r--lib/plum/server/http_connection.rb4
13 files changed, 15 insertions, 15 deletions
diff --git a/examples/client/twitter.rb b/examples/client/twitter.rb
index a67fad3..e029f59 100644
--- a/examples/client/twitter.rb
+++ b/examples/client/twitter.rb
@@ -24,7 +24,7 @@ Plum::Client.start("userstream.twitter.com", 443) { |streaming|
exit
end
- buf = String.new
+ buf = "".b
res.on_chunk { |chunk| # when received DATA frame
next if chunk.empty?
buf << chunk
diff --git a/examples/non_tls_server.rb b/examples/non_tls_server.rb
index e481b05..7ea7ad2 100644
--- a/examples/non_tls_server.rb
+++ b/examples/non_tls_server.rb
@@ -55,7 +55,7 @@ loop do
stream.on(:open) do
headers = nil
- data = String.new
+ data = "".b
end
stream.on(:headers) do |headers_|
diff --git a/examples/static_server.rb b/examples/static_server.rb
index 6f7e00a..0c61d96 100644
--- a/examples/static_server.rb
+++ b/examples/static_server.rb
@@ -75,7 +75,7 @@ loop do
stream.on(:open) do
headers = nil
- data = String.new
+ data = "".b
end
stream.on(:headers) do |headers_|
diff --git a/lib/plum/client/legacy_client_session.rb b/lib/plum/client/legacy_client_session.rb
index 9dea6cd..bdbce9a 100644
--- a/lib/plum/client/legacy_client_session.rb
+++ b/lib/plum/client/legacy_client_session.rb
@@ -68,7 +68,7 @@ module Plum
end
def construct_request(headers)
- out = String.new
+ out = "".b
out << "%s %s HTTP/1.1\r\n" % [headers[":method"], headers[":path"]]
headers.each { |key, value|
next if key.start_with?(":") # HTTP/2 psuedo headers
diff --git a/lib/plum/connection.rb b/lib/plum/connection.rb
index 2f177a6..739bbf3 100644
--- a/lib/plum/connection.rb
+++ b/lib/plum/connection.rb
@@ -27,7 +27,7 @@ module Plum
@writer = writer
@local_settings = Hash.new { |hash, key| DEFAULT_SETTINGS[key] }.merge!(local_settings)
@remote_settings = Hash.new { |hash, key| DEFAULT_SETTINGS[key] }
- @buffer = String.new
+ @buffer = "".b
@streams = {}
@hpack_decoder = HPACK::Decoder.new(@local_settings[:header_table_size])
@hpack_encoder = HPACK::Encoder.new(@remote_settings[:header_table_size])
diff --git a/lib/plum/frame/goaway.rb b/lib/plum/frame/goaway.rb
index e1e0097..5eeb28a 100644
--- a/lib/plum/frame/goaway.rb
+++ b/lib/plum/frame/goaway.rb
@@ -11,7 +11,7 @@ module Plum
# @param message [String] Additional debug data.
# @see RFC 7540 Section 6.8
def initialize(last_id, error_type, message = "")
- payload = String.new.push_uint32(last_id)
+ payload = "".b.push_uint32(last_id)
.push_uint32(HTTPError::ERROR_CODES[error_type])
.push(message)
initialize_base(type: :goaway, stream_id: 0, payload: payload)
diff --git a/lib/plum/frame/push_promise.rb b/lib/plum/frame/push_promise.rb
index e07b8e6..200fa37 100644
--- a/lib/plum/frame/push_promise.rb
+++ b/lib/plum/frame/push_promise.rb
@@ -11,7 +11,7 @@ module Plum
# @param encoded [String] Request headers.
# @param end_headers [Boolean] add END_HEADERS flag
def initialize(stream_id, new_id, encoded, end_headers: false)
- payload = String.new.push_uint32(new_id)
+ payload = "".b.push_uint32(new_id)
.push(encoded)
fval = end_headers ? 4 : 0
initialize_base(type: :push_promise, stream_id: stream_id, flags_value: fval, payload: payload)
diff --git a/lib/plum/frame/rst_stream.rb b/lib/plum/frame/rst_stream.rb
index a8004d5..c7794a9 100644
--- a/lib/plum/frame/rst_stream.rb
+++ b/lib/plum/frame/rst_stream.rb
@@ -9,7 +9,7 @@ module Plum
# @param stream_id [Integer] The stream ID.
# @param error_type [Symbol] The error type defined in RFC 7540 Section 7.
def initialize(stream_id, error_type)
- payload = String.new.push_uint32(HTTPError::ERROR_CODES[error_type])
+ payload = "".b.push_uint32(HTTPError::ERROR_CODES[error_type])
initialize_base(type: :rst_stream, stream_id: stream_id, payload: payload)
end
end
diff --git a/lib/plum/frame/settings.rb b/lib/plum/frame/settings.rb
index 7f7c2be..71a92eb 100644
--- a/lib/plum/frame/settings.rb
+++ b/lib/plum/frame/settings.rb
@@ -17,7 +17,7 @@ module Plum
# Creates a SETTINGS frame.
# @param args [Hash<Symbol, Integer>] The settings values to send.
def initialize(**args)
- payload = String.new
+ payload = "".b
args.each { |key, value|
id = SETTINGS_TYPE[key] or raise ArgumentError.new("invalid settings type: #{key}")
payload.push_uint16(id)
diff --git a/lib/plum/frame/window_update.rb b/lib/plum/frame/window_update.rb
index 6e36b2c..3fe5ecd 100644
--- a/lib/plum/frame/window_update.rb
+++ b/lib/plum/frame/window_update.rb
@@ -9,7 +9,7 @@ module Plum
# @param stream_id [Integer] the stream ID or 0.
# @param wsi [Integer] the amount to increase
def initialize(stream_id, wsi)
- payload = String.new.push_uint32(wsi)
+ payload = "".b.push_uint32(wsi)
initialize_base(type: :window_update, stream_id: stream_id, payload: payload)
end
end
diff --git a/lib/plum/hpack/huffman.rb b/lib/plum/hpack/huffman.rb
index 8fcc120..9604f1f 100644
--- a/lib/plum/hpack/huffman.rb
+++ b/lib/plum/hpack/huffman.rb
@@ -9,7 +9,7 @@ module Plum
# Static-Huffman-encodes the specified String.
def encode(bytestr)
- out = String.new
+ out = "".b
bytestr.each_byte do |b|
out << HUFFMAN_TABLE[b]
end
@@ -21,7 +21,7 @@ module Plum
def decode(encoded)
bits = encoded.unpack("B*")[0]
out = []
- buf = String.new
+ buf = "".b
bits.each_char do |cb|
buf << cb
if c = HUFFMAN_TABLE_INVERSED[buf]
diff --git a/lib/plum/rack/session.rb b/lib/plum/rack/session.rb
index d7e2f97..1c9a4df 100644
--- a/lib/plum/rack/session.rb
+++ b/lib/plum/rack/session.rb
@@ -55,7 +55,7 @@ module Plum
reqs = {}
@plum.on(:headers) { |stream, h|
- reqs[stream] = { headers: h, data: String.new.force_encoding(Encoding::BINARY) }
+ reqs[stream] = { headers: h, data: "".b }
}
@plum.on(:data) { |stream, d|
diff --git a/lib/plum/server/http_connection.rb b/lib/plum/server/http_connection.rb
index 1cf80dc..473cef6 100644
--- a/lib/plum/server/http_connection.rb
+++ b/lib/plum/server/http_connection.rb
@@ -6,7 +6,7 @@ module Plum
class HTTPServerConnection < ServerConnection
def initialize(writer, local_settings = {})
require "http/parser"
- @negobuf = String.new
+ @negobuf = "".b
@_http_parser = setup_parser
super(writer, local_settings)
end
@@ -22,7 +22,7 @@ module Plum
def setup_parser
headers = nil
- body = String.new
+ body = "".b
parser = HTTP::Parser.new
parser.on_headers_complete = proc { |_headers|