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.kgio.general Subject: [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage Date: Wed, 25 Sep 2013 19:42:38 +0000 Message-ID: <1380138159-5350-2-git-send-email-normalperson@yhbt.net> References: <1380138159-5350-1-git-send-email-normalperson@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 1380138177 6685 80.91.229.3 (25 Sep 2013 19:42:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Sep 2013 19:42:57 +0000 (UTC) To: kgio@librelist.org Original-X-From: kgio@librelist.org Wed Sep 25 21:43:01 2013 Return-path: Envelope-to: gclrkg-kgio@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: kgio@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.kgio.general:232 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VOuzE-0008PN-O8 for gclrkg-kgio@m.gmane.org; Wed, 25 Sep 2013 21:43:00 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 0C0C5750F3 for ; Wed, 25 Sep 2013 19:53:37 +0000 (UTC) From: Eric Wong 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