From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.raindrops.general Subject: [PATCH] linux_inet_diag: improve compatibility with newer GCs Date: Sun, 16 Jun 2013 20:59:25 +0000 Message-ID: <20130616205925.GA5569@dcvr.yhbt.net> References: <20130616205925.GA5569@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1371416371 31026 80.91.229.3 (16 Jun 2013 20:59:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 16 Jun 2013 20:59:31 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Sun Jun 16 22:59:33 2013 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org In-Reply-To: <20130616205925.GA5569@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: raindrops@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.raindrops.general:112 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UoK2s-0003jX-Uc for gclrrg-raindrops@m.gmane.org; Sun, 16 Jun 2013 22:59:31 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 7F11873DD8 for ; Sun, 16 Jun 2013 21:02:22 +0000 (UTC) RARRAY_PTR is expensive with GCs in Ruby 2.1.0dev and Rubinius, so use rb_ary_entry for non-performance critical paths. Eventually, RARRAY_AREF/RARRAY_ASET may be common, but for now, using rb_ary_entry should require the least cognitive overhead for a developer. --- Pushed to "gc-next" of git://bogomips.org/raindrops.git ext/raindrops/linux_inet_diag.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c index dcf7bc2..cd4a876 100644 --- a/ext/raindrops/linux_inet_diag.c +++ b/ext/raindrops/linux_inet_diag.c @@ -586,8 +586,6 @@ static VALUE tcp_stats(struct nogvl_args *args, VALUE addr) */ static VALUE tcp_listener_stats(int argc, VALUE *argv, VALUE self) { - VALUE *ary; - long i; VALUE rv = rb_hash_new(); struct nogvl_args args; VALUE addrs, sock; @@ -610,20 +608,26 @@ static VALUE tcp_listener_stats(int argc, VALUE *argv, VALUE self) case T_STRING: rb_hash_aset(rv, addrs, tcp_stats(&args, addrs)); return rv; - case T_ARRAY: - ary = RARRAY_PTR(addrs); - i = RARRAY_LEN(addrs); - if (i == 1) { - rb_hash_aset(rv, *ary, tcp_stats(&args, *ary)); + case T_ARRAY: { + long i; + long len = RARRAY_LEN(addrs); + VALUE cur; + + if (len == 1) { + cur = rb_ary_entry(addrs, 0); + + rb_hash_aset(rv, cur, tcp_stats(&args, cur)); return rv; } - for (; --i >= 0; ary++) { + for (i = 0; i < len; i++) { union any_addr check; + VALUE cur = rb_ary_entry(addrs, i); - parse_addr(&check, *ary); - rb_hash_aset(rv, *ary, Qtrue); + parse_addr(&check, cur); + rb_hash_aset(rv, cur, Qtrue); } /* fall through */ + } case T_NIL: args.table = st_init_strtable(); gen_bytecode_all(&args.iov[2]); -- Eric Wong