Skip to content

Commit 3d32739

Browse files
committed
ssl: refactor peeraddr_ip_str()
Remove an unnecessary instance variable lookup and constant lookup.
1 parent 2780599 commit 3d32739

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,26 +1590,24 @@ ossl_ssl_s_alloc(VALUE klass)
15901590
}
15911591

15921592
static VALUE
1593-
peer_ip_address(VALUE self)
1593+
peer_ip_address(VALUE io)
15941594
{
1595-
VALUE remote_address = rb_funcall(rb_attr_get(self, id_i_io), rb_intern("remote_address"), 0);
1595+
VALUE remote_address = rb_funcall(io, rb_intern("remote_address"), 0);
15961596

15971597
return rb_funcall(remote_address, rb_intern("inspect_sockaddr"), 0);
15981598
}
15991599

16001600
static VALUE
1601-
fallback_peer_ip_address(VALUE self, VALUE args)
1601+
fallback_peer_ip_address(VALUE io, VALUE args)
16021602
{
16031603
return rb_str_new_cstr("(null)");
16041604
}
16051605

16061606
static VALUE
1607-
peeraddr_ip_str(VALUE self)
1607+
peeraddr_ip_str(VALUE io)
16081608
{
1609-
VALUE rb_mErrno = rb_const_get(rb_cObject, rb_intern("Errno"));
1610-
VALUE rb_eSystemCallError = rb_const_get(rb_mErrno, rb_intern("SystemCallError"));
1611-
1612-
return rb_rescue2(peer_ip_address, self, fallback_peer_ip_address, (VALUE)0, rb_eSystemCallError, NULL);
1609+
return rb_rescue2(peer_ip_address, io, fallback_peer_ip_address, Qnil,
1610+
rb_eSystemCallError, (VALUE)0);
16131611
}
16141612

16151613
/*
@@ -1838,7 +1836,7 @@ ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
18381836
code == SSL_ERROR_SYSCALL ? " SYSCALL" : "",
18391837
code,
18401838
saved_errno,
1841-
peeraddr_ip_str(self),
1839+
peeraddr_ip_str(io),
18421840
SSL_state_string_long(ssl),
18431841
error_append);
18441842
}

0 commit comments

Comments
 (0)