From 0e98393a0933ab5564d5fb10644f46380a2eaac8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 26 Sep 2013 18:54:33 +0000 Subject: [PATCH] avoid RARRAY_PTR usage for vmsplice 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). --- ext/io_splice/io_splice_ext.c | 23 +++++++++-------------- 1 file 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) -- 2.11.4.GIT