* [PATCH 0/3] misc cleanups
@ 2016-12-29 7:42 Eric Wong
2016-12-29 7:42 ` [PATCH 1/3] avoid pointless capture in regexp Eric Wong
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2016-12-29 7:42 UTC (permalink / raw)
To: mogilefs-client-public
Nothing earth shattering, just 3 cleanups while I noticed
while working on other stuff...
3 changes:
avoid pointless capture in regexp
use opt_str_freeze to avoid allocations in a few places
new_file/common: simplify empty class declarations
lib/mogilefs/http_file.rb | 2 +-
lib/mogilefs/new_file/common.rb | 12 ++++++------
lib/mogilefs/new_file/stream.rb | 8 ++++----
lib/mogilefs/new_file/writer.rb | 2 +-
4 files changed, 12 insertions(+), 12 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] avoid pointless capture in regexp
2016-12-29 7:42 [PATCH 0/3] misc cleanups Eric Wong
@ 2016-12-29 7:42 ` Eric Wong
2016-12-29 7:42 ` [PATCH 2/3] use opt_str_freeze to avoid allocations in a few places Eric Wong
2016-12-29 7:42 ` [PATCH 3/3] new_file/common: simplify empty class declarations Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-12-29 7:42 UTC (permalink / raw)
To: mogilefs-client-public
We do not emit any sort of message on successful 2XX responses,
so there's no need to save the actual response after writing.
---
lib/mogilefs/new_file/common.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/mogilefs/new_file/common.rb b/lib/mogilefs/new_file/common.rb
index c102901..44eee69 100644
--- a/lib/mogilefs/new_file/common.rb
+++ b/lib/mogilefs/new_file/common.rb
@@ -23,7 +23,7 @@ def read_response(sock)
start_time = @opts[:start_time] and tout -= MogileFS.now - start_time
set_socket_options(sock)
case line = sock.timed_read(23, "", tout > 0.0 ? tout : 0)
- when %r{^HTTP/\d\.\d\s+(2\d\d)\s} # success!
+ when %r{^HTTP/\d\.\d\s+(?:2\d\d)\s} # success!
when nil
raise EmptyResponseError, 'Unable to read response line from server'
when %r{^HTTP/\d\.\d\s+(\d+)}
--
EW
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] use opt_str_freeze to avoid allocations in a few places
2016-12-29 7:42 [PATCH 0/3] misc cleanups Eric Wong
2016-12-29 7:42 ` [PATCH 1/3] avoid pointless capture in regexp Eric Wong
@ 2016-12-29 7:42 ` Eric Wong
2016-12-29 7:42 ` [PATCH 3/3] new_file/common: simplify empty class declarations Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-12-29 7:42 UTC (permalink / raw)
To: mogilefs-client-public
None of these are too performance critical, but err on
the safe side and avoid allocations whenever possible.
---
lib/mogilefs/http_file.rb | 2 +-
lib/mogilefs/new_file/stream.rb | 8 ++++----
lib/mogilefs/new_file/writer.rb | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/mogilefs/http_file.rb b/lib/mogilefs/http_file.rb
index caf85ca..c7949a5 100644
--- a/lib/mogilefs/http_file.rb
+++ b/lib/mogilefs/http_file.rb
@@ -143,7 +143,7 @@ def nhp_put(devid, uri)
end
put = Net::HTTP::Put.new(uri.path)
- put["Content-Type"] = "application/octet-stream"
+ put["Content-Type"] = "application/octet-stream".freeze
if md5 = @opts[:content_md5]
if md5.respond_to?(:call)
md5 = md5.call.strip
diff --git a/lib/mogilefs/new_file/stream.rb b/lib/mogilefs/new_file/stream.rb
index 71ac591..195b121 100644
--- a/lib/mogilefs/new_file/stream.rb
+++ b/lib/mogilefs/new_file/stream.rb
@@ -66,7 +66,7 @@ def commit
def start_sock(sock, uri)
host_with_port = "#{uri.host}:#{uri.port}"
headers = "PUT #{uri.request_uri} HTTP/1.1\r\n" \
- "Host: #{host_with_port}\r\n" \
+ "Host: #{host_with_port}\r\n"
content_md5 = @opts[:content_md5]
if String === content_md5
@@ -75,16 +75,16 @@ def start_sock(sock, uri)
:trailer == content_md5 ||
MD5_TRAILER_NODES[host_with_port]
@md5 = Digest::MD5.new
- headers << "Trailer: Content-MD5\r\n"
+ headers << "Trailer: Content-MD5\r\n".freeze
end
if ! @md5 && clen = @opts[:content_length]
headers << "Content-Length: #{clen}\r\n"
else
- headers << "Transfer-Encoding: chunked\r\n"
+ headers << "Transfer-Encoding: chunked\r\n".freeze
end
- sock.write(headers << "\r\n")
+ sock.write(headers << "\r\n".freeze)
end
alias syswrite write
diff --git a/lib/mogilefs/new_file/writer.rb b/lib/mogilefs/new_file/writer.rb
index d58a4e6..e2f13fc 100644
--- a/lib/mogilefs/new_file/writer.rb
+++ b/lib/mogilefs/new_file/writer.rb
@@ -9,7 +9,7 @@ module MogileFS::NewFile::Writer
def puts(*args)
args.each do |obj|
write(obj)
- write("\n")
+ write("\n".freeze)
end
nil
end
--
EW
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] new_file/common: simplify empty class declarations
2016-12-29 7:42 [PATCH 0/3] misc cleanups Eric Wong
2016-12-29 7:42 ` [PATCH 1/3] avoid pointless capture in regexp Eric Wong
2016-12-29 7:42 ` [PATCH 2/3] use opt_str_freeze to avoid allocations in a few places Eric Wong
@ 2016-12-29 7:42 ` Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-12-29 7:42 UTC (permalink / raw)
To: mogilefs-client-public
This compiles to smaller bytecode on YARV (MRI)
---
lib/mogilefs/new_file/common.rb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/mogilefs/new_file/common.rb b/lib/mogilefs/new_file/common.rb
index 44eee69..d696072 100644
--- a/lib/mogilefs/new_file/common.rb
+++ b/lib/mogilefs/new_file/common.rb
@@ -7,14 +7,14 @@
module MogileFS::NewFile::Common
# :stopdoc:
- class RetryableError < MogileFS::Error; end
- class EmptyResponseError < RetryableError; end
- class BadResponseError < RetryableError; end
- class UnparseableResponseError < RetryableError; end
+ RetryableError = Class.new(MogileFS::Error)
+ EmptyResponseError = Class.new(RetryableError)
+ BadResponseError = Class.new(RetryableError)
+ UnparseableResponseError = Class.new(RetryableError)
class NoStorageNodesError < MogileFS::Error
def message; 'Unable to open socket to storage node'; end
end
- class NonRetryableError < MogileFS::Error; end
+ NonRetryableError = Class.new(MogileFS::Error)
MD5_TRAILER_NODES = {} # :nodoc: # EXPERIMENTAL
--
EW
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-29 7:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-29 7:42 [PATCH 0/3] misc cleanups Eric Wong
2016-12-29 7:42 ` [PATCH 1/3] avoid pointless capture in regexp Eric Wong
2016-12-29 7:42 ` [PATCH 2/3] use opt_str_freeze to avoid allocations in a few places Eric Wong
2016-12-29 7:42 ` [PATCH 3/3] new_file/common: simplify empty class declarations Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/mogilefs-client.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).