about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-02-05 01:17:51 +0000
committerEric Wong <e@80x24.org>2015-02-05 17:18:11 +0000
commit28bb0e47541e49f36b96725732f7a7ae260bd5e9 (patch)
treed3997bef4d5912bff580b916c1dce2905d6b7821 /test
parentfe83ead4eae6f011fa15f506cd80cb4256813a92 (diff)
downloadunicorn-28bb0e47541e49f36b96725732f7a7ae260bd5e9.tar.gz
In Ruby 1.9.2+, socket options may be specified using symbols
instead of constants to avoid the need to import Socket::Constants
into the namespace.  This also has a nice side-effect of reducing
the size of the bytecode by trading 3 instructions (getinlinecache,
getconstant, setinlinecache) for one "putobject" instruction.

Nowadays, we may also avoid defining OS-specific constants ourselves
since 1.9+ versions of Ruby already provide them to further reduce
bytecode size.

getsockopt also returns Socket::Option objects in 1.9.2+,
allowing us to avoid the larger "unpack('i')" method dispatch
for an operand-free "int" method call.

Finally, favor Object#nil? calls rather than "== nil" comparisons
to reduce bytecode size even more.

Since this code is only called at startup time, it does not benefit
from inline caching of constant lookups in current mainline Ruby.

Combined, these changes reduce YARV bytecode size by around 2K on a
64-bit system.
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_socket_helper.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/test/unit/test_socket_helper.rb b/test/unit/test_socket_helper.rb
index 8992757..dd6881c 100644
--- a/test/unit/test_socket_helper.rb
+++ b/test/unit/test_socket_helper.rb
@@ -189,7 +189,7 @@ class TestSocketHelper < Test::Unit::TestCase
     port = unused_port @test_addr
     name = "#@test_addr:#{port}"
     sock = bind_listen(name, :reuseport => true)
-    cur = sock.getsockopt(Socket::SOL_SOCKET, SO_REUSEPORT).unpack('i')[0]
+    cur = sock.getsockopt(:SOL_SOCKET, :SO_REUSEPORT).int
     assert_operator cur, :>, 0
   rescue Errno::ENOPROTOOPT
     # kernel does not support SO_REUSEPORT (older Linux)