kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: kgio@librelist.org
Subject: [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage
Date: Wed, 25 Sep 2013 19:43:04 +0000	[thread overview]
Message-ID: <1380138185-5435-2-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1380138185-5435-1-git-send-email-normalperson@yhbt.net

From: Eric Wong <e@yhbt.net>

I have not benchmarked this, but this should not make a difference
as far as performance goes.  This should also allow better
performance of better GCs in Ruby 2.1.0 and Rubinius.
---
 ext/kgio/ancient_ruby.h |  3 ---
 ext/kgio/read_write.c   | 12 +++++-------
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/ext/kgio/ancient_ruby.h b/ext/kgio/ancient_ruby.h
index cda0917..fb0a80b 100644
--- a/ext/kgio/ancient_ruby.h
+++ b/ext/kgio/ancient_ruby.h
@@ -17,9 +17,6 @@ static void my_str_set_len(VALUE str, long len)
 #  define RSTRING_LEN(s) (RSTRING(s)->len)
 #endif /* !defined(RSTRING_LEN) */
 
-#ifndef RARRAY_PTR
-#  define RARRAY_PTR(s) (RARRAY(s)->ptr)
-#endif /* !defined(RARRAY_PTR) */
 #ifndef RARRAY_LEN
 #  define RARRAY_LEN(s) (RARRAY(s)->len)
 #endif /* !defined(RARRAY_LEN) */
diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c
index f4d658c..34c619f 100644
--- a/ext/kgio/read_write.c
+++ b/ext/kgio/read_write.c
@@ -521,9 +521,7 @@ static void fill_iovec(struct io_args_v *a)
 	curvec = a->vec = (struct iovec*)RSTRING_PTR(a->vec_buf);
 
 	for (i=0; i < a->iov_cnt; i++, curvec++) {
-		/* rb_ary_store could reallocate array,
-		 * so that ought to use RARRAY_PTR */
-		VALUE str = RARRAY_PTR(a->buf)[i];
+		VALUE str = rb_ary_entry(a->buf, i);
 		long str_len, next_len;
 
 		if (TYPE(str) != T_STRING) {
@@ -551,14 +549,14 @@ static long trim_writev_buffer(struct io_args_v *a, long n)
 {
 	long i;
 	long ary_len = RARRAY_LEN(a->buf);
-	VALUE *elem = RARRAY_PTR(a->buf);
 
 	if (n == (long)a->batch_len) {
 		i = a->iov_cnt;
 		n = 0;
 	} else {
-		for (i = 0; n && i < ary_len; i++, elem++) {
-			n -= RSTRING_LEN(*elem);
+		for (i = 0; n && i < ary_len; i++) {
+			VALUE entry = rb_ary_entry(a->buf, i);
+			n -= RSTRING_LEN(entry);
 			if (n < 0) break;
 		}
 	}
@@ -576,7 +574,7 @@ static long trim_writev_buffer(struct io_args_v *a, long n)
 
 	/* setup+replace partially written buffer */
 	if (n < 0) {
-		VALUE str = RARRAY_PTR(a->buf)[0];
+		VALUE str = rb_ary_entry(a->buf, 0);
 		long str_len = RSTRING_LEN(str);
 		str = rb_str_subseq(str, str_len + n, -n);
 		rb_ary_store(a->buf, 0, str);
-- 
1.8.3.2.701.g8c4e4ec



  reply	other threads:[~2013-09-25 19:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-25 19:43 [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 19:43 ` Eric Wong [this message]
2013-09-25 19:43 ` [PATCH 3/3] my_writev: stylistic fixes Eric Wong
2013-09-25 19:44 ` [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 21:37 ` Aeon
2013-09-25 22:00   ` Eric Wong
2013-09-26  3:02     ` Aeon
  -- strict thread matches above, loose matches on Subject: below --
2013-09-25 19:42 Eric Wong
2013-09-25 19:42 ` [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage 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/kgio/

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

  git send-email \
    --in-reply-to=1380138185-5435-2-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=kgio@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/kgio.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).