* [PATCH] avoid RARRAY_PTR usage for vmsplice
@ 2013-09-26 19:15 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2013-09-26 19:15 UTC (permalink / raw)
To: ruby.io.splice
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)
--
Eric Wong
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-09-26 19:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-26 19:15 [PATCH] avoid RARRAY_PTR usage for vmsplice Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/ruby_io_splice.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).