about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-09-26 18:54:33 +0000
committerEric Wong <normalperson@yhbt.net>2013-09-26 18:54:33 +0000
commit0e98393a0933ab5564d5fb10644f46380a2eaac8 (patch)
tree8329fcaf078560e6865a6a22df582accb2f68522
parent8b8c743f6a4ce3d1f61b3d4a59f9512593596146 (diff)
downloadruby_io_splice-0e98393a0933ab5564d5fb10644f46380a2eaac8.tar.gz
In case somebody finds vmsplice useful in Ruby, we avoid incurring
the performance loss from RARRAY_PTR under Ruby 2.1.0 and Rubinius.
However, I still haven't found a useful use of vmsplice under
Ruby (or any high-level languages).
-rw-r--r--ext/io_splice/io_splice_ext.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c
index 1c938c3..9a838df 100644
--- a/ext/io_splice/io_splice_ext.c
+++ b/ext/io_splice/io_splice_ext.c
@@ -108,9 +108,6 @@ rb_thread_blocking_region(
 #ifndef RSTRING_LEN
 #  define RSTRING_LEN(s) (RSTRING(s)->len)
 #endif
-#ifndef RARRAY_PTR
-#  define RARRAY_PTR(s) (RARRAY(s)->ptr)
-#endif
 #ifndef RARRAY_LEN
 #  define RARRAY_LEN(s) (RARRAY(s)->len)
 #endif
@@ -416,20 +413,18 @@ static VALUE nogvl_vmsplice(void *ptr)
 /* this can't be a function since we use alloca() */
 #define ARY2IOVEC(iov,iovcnt,expect,ary) \
 do { \
-        VALUE *cur; \
         struct iovec *tmp; \
-        long n; \
-        cur = RARRAY_PTR(ary); \
-        n = RARRAY_LEN(ary); \
-        if (n > IOV_MAX) \
+        unsigned long i; \
+        iovcnt = (unsigned long)RARRAY_LEN(ary); \
+        if (iovcnt > IOV_MAX) \
                 rb_raise(rb_eArgError, "array is larger than IOV_MAX"); \
-        iov = tmp = alloca(sizeof(struct iovec) * n); \
+        iov = tmp = alloca(sizeof(struct iovec) * iovcnt); \
         expect = 0; \
-        iovcnt = n; \
-        for (; --n >= 0; tmp++, cur++) { \
-                Check_Type(*cur, T_STRING); \
-                tmp->iov_base = RSTRING_PTR(*cur); \
-                tmp->iov_len = RSTRING_LEN(*cur); \
+        for (i = 0; i < iovcnt; tmp++, i++) { \
+                VALUE cur = rb_ary_entry(ary, (long)i); \
+                Check_Type(cur, T_STRING); \
+                tmp->iov_base = RSTRING_PTR(cur); \
+                tmp->iov_len = RSTRING_LEN(cur); \
                 expect += tmp->iov_len; \
         } \
 } while (0)