* [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init
@ 2013-09-25 19:43 Eric Wong
2013-09-25 19:43 ` [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage Eric Wong
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Eric Wong @ 2013-09-25 19:43 UTC (permalink / raw)
To: kgio
From: Eric Wong <e@yhbt.net>
This is trivially non-performance-critical, and can only
help with advanced GCs in Ruby 2.1.0 and Rubinius
---
ext/kgio/tryopen.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
index 5fa6ada..902c745 100644
--- a/ext/kgio/tryopen.c
+++ b/ext/kgio/tryopen.c
@@ -135,8 +135,7 @@ void init_kgio_tryopen(void)
VALUE mPipeMethods = rb_const_get(mKgio, rb_intern("PipeMethods"));
VALUE cFile;
VALUE tmp;
- VALUE *ptr;
- long len;
+ long i, len;
id_path = rb_intern("path");
id_for_fd = rb_intern("for_fd");
@@ -161,15 +160,15 @@ void init_kgio_tryopen(void)
errno2sym = st_init_numtable();
tmp = rb_funcall(rb_mErrno, rb_intern("constants"), 0);
- ptr = RARRAY_PTR(tmp);
len = RARRAY_LEN(tmp);
- for (; --len >= 0; ptr++) {
+ for (i = 0; i < len; i++) {
VALUE error;
+ VALUE err = rb_ary_entry(tmp, i);
ID const_id;
- switch (TYPE(*ptr)) {
- case T_SYMBOL: const_id = SYM2ID(*ptr); break;
- case T_STRING: const_id = rb_intern(RSTRING_PTR(*ptr)); break;
+ switch (TYPE(err)) {
+ case T_SYMBOL: const_id = SYM2ID(err); break;
+ case T_STRING: const_id = rb_intern(RSTRING_PTR(err)); break;
default: rb_bug("constant not a symbol or string");
}
--
1.8.3.2.701.g8c4e4ec
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage
2013-09-25 19:43 [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
@ 2013-09-25 19:43 ` Eric Wong
2013-09-25 19:43 ` [PATCH 3/3] my_writev: stylistic fixes Eric Wong
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2013-09-25 19:43 UTC (permalink / raw)
To: kgio
From: Eric Wong <e@yhbt.net>
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);
--
1.8.3.2.701.g8c4e4ec
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] my_writev: stylistic fixes
2013-09-25 19:43 [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 19:43 ` [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage Eric Wong
@ 2013-09-25 19:43 ` Eric Wong
2013-09-25 19:44 ` [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 21:37 ` Aeon
3 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2013-09-25 19:43 UTC (permalink / raw)
To: kgio
From: Eric Wong <e@yhbt.net>
Rename 'str' to 'ary', as that's the whole point of supporting
writev... Also, long lines need to be wrapped at 80 columns
---
ext/kgio/read_write.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c
index 34c619f..fcb48bb 100644
--- a/ext/kgio/read_write.c
+++ b/ext/kgio/read_write.c
@@ -606,12 +606,12 @@ static int writev_check(struct io_args_v *a, long n, const char *msg, int io_wai
return 0;
}
-static VALUE my_writev(VALUE io, VALUE str, int io_wait)
+static VALUE my_writev(VALUE io, VALUE ary, int io_wait)
{
struct io_args_v a;
long n;
- prepare_writev(&a, io, str);
+ prepare_writev(&a, io, ary);
set_nonblocking(a.fd);
do {
@@ -619,12 +619,15 @@ static VALUE my_writev(VALUE io, VALUE str, int io_wait)
if (a.iov_cnt == 0)
n = 0;
else if (a.iov_cnt == 1)
- n = (long)write(a.fd, a.vec[0].iov_base, a.vec[0].iov_len);
+ n = (long)write(a.fd, a.vec[0].iov_base,
+ a.vec[0].iov_len);
/* for big strings use library function */
- else if (USE_WRITEV && a.batch_len / WRITEV_IMPL_THRESHOLD > a.iov_cnt)
+ else if (USE_WRITEV &&
+ ((a.batch_len / WRITEV_IMPL_THRESHOLD) > a.iov_cnt))
n = (long)writev(a.fd, a.vec, a.iov_cnt);
else
- n = (long)custom_writev(a.fd, a.vec, a.iov_cnt, a.batch_len);
+ n = (long)custom_writev(a.fd, a.vec, a.iov_cnt,
+ a.batch_len);
} while (writev_check(&a, n, "writev", io_wait) != 0);
rb_str_resize(a.vec_buf, 0);
--
1.8.3.2.701.g8c4e4ec
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init
2013-09-25 19:43 [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 19:43 ` [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage Eric Wong
2013-09-25 19:43 ` [PATCH 3/3] my_writev: stylistic fixes Eric Wong
@ 2013-09-25 19:44 ` Eric Wong
2013-09-25 21:37 ` Aeon
3 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2013-09-25 19:44 UTC (permalink / raw)
To: kgio
Oops, sorry for the double git-send-email. Too much coffee makes
me twitchy :x
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init
2013-09-25 19:43 [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
` (2 preceding siblings ...)
2013-09-25 19:44 ` [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
@ 2013-09-25 21:37 ` Aeon
2013-09-25 22:00 ` Eric Wong
3 siblings, 1 reply; 8+ messages in thread
From: Aeon @ 2013-09-25 21:37 UTC (permalink / raw)
To: kgio
How can I unsubscribe from this list?
I am not even sure where I got signed up.
-Aaron
On Wed, Sep 25, 2013 at 2:43 PM, Eric Wong <normalperson@yhbt.net> wrote:
> From: Eric Wong <e@yhbt.net>
>
> This is trivially non-performance-critical, and can only
> help with advanced GCs in Ruby 2.1.0 and Rubinius
> ---
> ext/kgio/tryopen.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
> index 5fa6ada..902c745 100644
> --- a/ext/kgio/tryopen.c
> +++ b/ext/kgio/tryopen.c
> @@ -135,8 +135,7 @@ void init_kgio_tryopen(void)
> VALUE mPipeMethods = rb_const_get(mKgio, rb_intern("PipeMethods"));
> VALUE cFile;
> VALUE tmp;
> - VALUE *ptr;
> - long len;
> + long i, len;
>
> id_path = rb_intern("path");
> id_for_fd = rb_intern("for_fd");
> @@ -161,15 +160,15 @@ void init_kgio_tryopen(void)
>
> errno2sym = st_init_numtable();
> tmp = rb_funcall(rb_mErrno, rb_intern("constants"), 0);
> - ptr = RARRAY_PTR(tmp);
> len = RARRAY_LEN(tmp);
> - for (; --len >= 0; ptr++) {
> + for (i = 0; i < len; i++) {
> VALUE error;
> + VALUE err = rb_ary_entry(tmp, i);
> ID const_id;
>
> - switch (TYPE(*ptr)) {
> - case T_SYMBOL: const_id = SYM2ID(*ptr); break;
> - case T_STRING: const_id = rb_intern(RSTRING_PTR(*ptr));
> break;
> + switch (TYPE(err)) {
> + case T_SYMBOL: const_id = SYM2ID(err); break;
> + case T_STRING: const_id = rb_intern(RSTRING_PTR(err));
> break;
> default: rb_bug("constant not a symbol or string");
> }
>
> --
> 1.8.3.2.701.g8c4e4ec
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init
@ 2013-09-25 19:42 Eric Wong
0 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2013-09-25 19:42 UTC (permalink / raw)
To: kgio
From: Eric Wong <e@yhbt.net>
This is trivially non-performance-critical, and can only
help with advanced GCs in Ruby 2.1.0 and Rubinius
---
ext/kgio/tryopen.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
index 5fa6ada..902c745 100644
--- a/ext/kgio/tryopen.c
+++ b/ext/kgio/tryopen.c
@@ -135,8 +135,7 @@ void init_kgio_tryopen(void)
VALUE mPipeMethods = rb_const_get(mKgio, rb_intern("PipeMethods"));
VALUE cFile;
VALUE tmp;
- VALUE *ptr;
- long len;
+ long i, len;
id_path = rb_intern("path");
id_for_fd = rb_intern("for_fd");
@@ -161,15 +160,15 @@ void init_kgio_tryopen(void)
errno2sym = st_init_numtable();
tmp = rb_funcall(rb_mErrno, rb_intern("constants"), 0);
- ptr = RARRAY_PTR(tmp);
len = RARRAY_LEN(tmp);
- for (; --len >= 0; ptr++) {
+ for (i = 0; i < len; i++) {
VALUE error;
+ VALUE err = rb_ary_entry(tmp, i);
ID const_id;
- switch (TYPE(*ptr)) {
- case T_SYMBOL: const_id = SYM2ID(*ptr); break;
- case T_STRING: const_id = rb_intern(RSTRING_PTR(*ptr)); break;
+ switch (TYPE(err)) {
+ case T_SYMBOL: const_id = SYM2ID(err); break;
+ case T_STRING: const_id = rb_intern(RSTRING_PTR(err)); break;
default: rb_bug("constant not a symbol or string");
}
--
1.8.3.2.701.g8c4e4ec
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-09-26 3:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-25 19:43 [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 19:43 ` [PATCH 2/3] read_write: remove the rest of RARRAY_PTR usage Eric Wong
2013-09-25 19:43 ` [PATCH 3/3] my_writev: stylistic fixes Eric Wong
2013-09-25 19:44 ` [PATCH 1/3] tryopen: remove RARRAY_PTR usage in init Eric Wong
2013-09-25 21:37 ` Aeon
2013-09-25 22:00 ` Eric Wong
2013-09-26 3:02 ` Aeon
-- strict thread matches above, loose matches on Subject: below --
2013-09-25 19:42 Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/kgio.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).