sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.org
Subject: [sleepy.penguin] [PATCH 2/3] avoid RARRAY_PTR usage for Linux-only bits
Date: Thu, 26 Sep 2013 21:39:59 +0000	[thread overview]
Message-ID: <1380231600-27298-2-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1380231600-27298-1-git-send-email-normalperson@yhbt.net

RARRAY_PTR incurs extra overhead on the Ruby 2.1.0 and Rubinius
GC implementations, so avoid it.  None of these are believed
to be performance-critical enough to benefit from RARRAY_PTR
in older Rubies, either.
---
 ext/sleepy_penguin/inotify.c  |  8 ++++----
 ext/sleepy_penguin/signalfd.c |  6 +++---
 ext/sleepy_penguin/util.c     | 12 ++++++------
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c
index 4e771a2..5771030 100644
--- a/ext/sleepy_penguin/inotify.c
+++ b/ext/sleepy_penguin/inotify.c
@@ -255,15 +255,15 @@ static VALUE take(int argc, VALUE *argv, VALUE self)
 static VALUE events(VALUE self)
 {
 	long len = RARRAY_LEN(checks);
-	VALUE *ptr = RARRAY_PTR(checks);
+	long i;
 	VALUE sym;
 	VALUE rv = rb_ary_new();
 	uint32_t mask;
 	uint32_t event_mask = NUM2UINT(rb_funcall(self, id_mask, 0));
 
-	for (; (len -= 2) >= 0;) {
-		sym = *ptr++;
-		mask = NUM2UINT(*ptr++);
+	for (i = 0; i < len; ) {
+		sym = rb_ary_entry(checks, i++);
+		mask = NUM2UINT(rb_ary_entry(checks, i++));
 		if ((event_mask & mask) == mask)
 			rb_ary_push(rv, sym);
 	}
diff --git a/ext/sleepy_penguin/signalfd.c b/ext/sleepy_penguin/signalfd.c
index 511745c..ebd6c86 100644
--- a/ext/sleepy_penguin/signalfd.c
+++ b/ext/sleepy_penguin/signalfd.c
@@ -44,11 +44,11 @@ static void value2sigset(sigset_t *mask, VALUE set)
 	switch (TYPE(set)) {
 	case T_NIL: return;
 	case T_ARRAY: {
-		VALUE *ptr = RARRAY_PTR(set);
+		long i;
 		long len = RARRAY_LEN(set);
 
-		while (--len >= 0)
-			sigaddset(mask, sig2int(*ptr++));
+		for (i = 0; i < len; i++)
+			sigaddset(mask, sig2int(rb_ary_entry(set, i)));
 		}
 		break;
 	default:
diff --git a/ext/sleepy_penguin/util.c b/ext/sleepy_penguin/util.c
index 11a1b13..717a099 100644
--- a/ext/sleepy_penguin/util.c
+++ b/ext/sleepy_penguin/util.c
@@ -14,13 +14,13 @@ int rb_sp_get_flags(VALUE klass, VALUE flags, int default_flags)
 	case T_SYMBOL:
 		return NUM2INT(rb_const_get(klass_for(klass), SYM2ID(flags)));
 	case T_ARRAY: {
-		VALUE *ptr = RARRAY_PTR(flags);
+		long i;
 		long len = RARRAY_LEN(flags);
 		int rv = 0;
 
 		klass = klass_for(klass);
-		while (--len >= 0) {
-			VALUE tmp = *ptr++;
+		for (i = 0; i < len; i++) {
+			VALUE tmp = rb_ary_entry(flags, i);
 
 			Check_Type(tmp, T_SYMBOL);
 			tmp = rb_const_get(klass, SYM2ID(tmp));
@@ -42,13 +42,13 @@ unsigned rb_sp_get_uflags(VALUE klass, VALUE flags)
 	case T_SYMBOL:
 		return NUM2UINT(rb_const_get(klass_for(klass), SYM2ID(flags)));
 	case T_ARRAY: {
-		VALUE *ptr = RARRAY_PTR(flags);
+		long i;
 		long len = RARRAY_LEN(flags);
 		unsigned rv = 0;
 
 		klass = klass_for(klass);
-		while (--len >= 0) {
-			VALUE tmp = *ptr++;
+		for (i = 0; i < len; i++) {
+			VALUE tmp = rb_ary_entry(flags, i);
 
 			Check_Type(tmp, T_SYMBOL);
 			tmp = rb_const_get(klass, SYM2ID(tmp));
-- 
1.8.4



  reply	other threads:[~2013-09-26 21:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-26 21:39 [sleepy.penguin] [PATCH 1/3] test_epoll: minor compatibility fix for Ruby 2.1.0 Eric Wong
2013-09-26 21:39 ` Eric Wong [this message]
2013-09-26 21:40 ` [sleepy.penguin] [PATCH 3/3] init: avoid redefinition warning for _GNU_SOURCE Eric Wong

Reply instructions:

You may reply publicly 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://yhbt.net/sleepy_penguin/

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

  git send-email \
    --in-reply-to=1380231600-27298-2-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=sleepy.penguin@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).