raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: raindrops@librelist.org
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> (raw)
In-Reply-To: <20130616205925.GA5569@dcvr.yhbt.net>

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


       reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-16 20:59 Eric Wong [this message]
2013-08-31  6:02 ` Eric Wong

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://bogomips.org/raindrops/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130616205925.GA5569@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=raindrops@librelist.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

raindrops RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/raindrops-public
	git clone --mirror http://ou63pmih66umazou.onion/raindrops-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.raindrops
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.raindrops

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox