about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2013-09-25 19:26:26 +0000
committerEric Wong <normalperson@yhbt.net>2013-09-25 19:41:27 +0000
commit13725d97e0c493cc38a4c833c1053216fb5c799b (patch)
tree542121d811ccbce92f1f609b90f639b298d44970
parente0d3b3cbe90b47facf0e67036429502ad8f99c49 (diff)
downloadkgio-13725d97e0c493cc38a4c833c1053216fb5c799b.tar.gz
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.
-rw-r--r--ext/kgio/ancient_ruby.h3
-rw-r--r--ext/kgio/read_write.c12
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);