From 13725d97e0c493cc38a4c833c1053216fb5c799b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 25 Sep 2013 19:26:26 +0000 Subject: read_write: remove the rest of RARRAY_PTR usage 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); -- cgit v1.2.3-24-ge0c7