[前][次][番号順一覧][スレッド一覧]

ruby-changes:37873

From: normal <ko1@a...>
Date: Fri, 13 Mar 2015 07:07:30 +0900 (JST)
Subject: [ruby-changes:37873] normal:r49955 (trunk): accept_nonblock: favor rb_hash_lookup2 to avoid Hash#default

normal	2015-03-13 07:04:24 +0900 (Fri, 13 Mar 2015)

  New Revision: 49955

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49955

  Log:
    accept_nonblock: favor rb_hash_lookup2 to avoid Hash#default
    
    * ext/socket/init.c (rsock_s_accept_nonblock): use rb_hash_lookup2
    * ext/openssl/ossl_ssl.c (get_no_exception): new function
      (ossl_ssl_accept_nonblock): use get_no_exception
      (ossl_ssl_read_internal): ditto
      (ossl_ssl_write_nonblock): ditto

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_ssl.c
    trunk/ext/socket/init.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49954)
+++ ChangeLog	(revision 49955)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Mar 13 07:02:20 2015  Eric Wong  <e@8...>
+
+	* ext/socket/init.c (rsock_s_accept_nonblock): use rb_hash_lookup2
+	* ext/openssl/ossl_ssl.c (get_no_exception): new function
+	  (ossl_ssl_accept_nonblock): use get_no_exception
+	  (ossl_ssl_read_internal): ditto
+	  (ossl_ssl_write_nonblock): ditto
+	  [ruby-core:68511]
+
 Fri Mar 13 07:01:38 2015  Eric Wong  <e@8...>
 
 	* ext/openssl/ossl_ssl.c: predefine wait_*able symbols
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 49954)
+++ ext/openssl/ossl_ssl.c	(revision 49955)
@@ -1369,6 +1369,14 @@ ossl_ssl_accept(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1369
     return ossl_start_ssl(self, SSL_accept, "SSL_accept", 0, 0);
 }
 
+static int
+get_no_exception(VALUE opts)
+{
+    if (!NIL_P(opts) && Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
+	return 1;
+    return 0;
+}
+
 /*
  * call-seq:
  *    ssl.accept_nonblock([options]) => self
@@ -1394,13 +1402,11 @@ ossl_ssl_accept(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1402
 static VALUE
 ossl_ssl_accept_nonblock(int argc, VALUE *argv, VALUE self)
 {
-    int no_exception = 0;
+    int no_exception;
     VALUE opts = Qnil;
 
     rb_scan_args(argc, argv, "0:", &opts);
-
-    if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
-	no_exception = 1;
+    no_exception = get_no_exception(opts);
 
     ossl_ssl_setup(self);
     return ossl_start_ssl(self, SSL_accept, "SSL_accept", 1, no_exception);
@@ -1411,15 +1417,13 @@ ossl_ssl_read_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1417
 {
     SSL *ssl;
     int ilen, nread = 0;
-    int no_exception = 0;
+    int no_exception;
     VALUE len, str;
     rb_io_t *fptr;
     VALUE opts = Qnil;
 
     rb_scan_args(argc, argv, "11:", &len, &str, &opts);
-
-    if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
-	no_exception = 1;
+    no_exception = get_no_exception(opts);
 
     ilen = NUM2INT(len);
     if(NIL_P(str)) str = rb_str_new(0, ilen);
@@ -1582,12 +1586,10 @@ ossl_ssl_write_nonblock(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1586
 {
     VALUE str;
     VALUE opts = Qnil;
-    int no_exception = 0;
+    int no_exception;
 
     rb_scan_args(argc, argv, "1:", &str, &opts);
-
-    if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
-	no_exception = 1;
+    no_exception = get_no_exception(opts);
 
     return ossl_ssl_write_internal(self, str, 1, no_exception);
 }
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 49954)
+++ ext/socket/init.c	(revision 49955)
@@ -516,7 +516,7 @@ rsock_s_accept_nonblock(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L516
 
     rb_scan_args(argc, argv, "0:", &opts);
 
-    if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
+    if (!NIL_P(opts) && Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
 	ex = 0;
 
     rb_secure(3);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]