kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Sokolov Yura 'funny-falcon <funny.falcon@gmail.com>
To: kgio@librelist.com
Subject: [PATCH 2/3] use rb_str_subseq for tail string on write
Date: Wed, 30 May 2012 17:56:55 +0400	[thread overview]
Message-ID: <1338386216-14568-2-git-send-email-funny.falcon@gmail.com> (raw)
In-Reply-To: 1338386216-14568-1-git-send-email-funny.falcon@gmail.com

Use rb_str_subseq for taking string's tail. rb_str_subseq do not allocate
additional memory in this case. And although it prevents from collecting
original string, it seems that tests wins both in performance and in memory
usage.

Use fallback to rb_str_substr on ruby1.8
---
 ext/kgio/extconf.rb   |    1 +
 ext/kgio/read_write.c |    5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/ext/kgio/extconf.rb b/ext/kgio/extconf.rb
index fb680f7..f6bd0cc 100644
--- a/ext/kgio/extconf.rb
+++ b/ext/kgio/extconf.rb
@@ -49,5 +49,6 @@ have_func('rb_thread_io_blocking_region')
 have_func('rb_str_set_len')
 have_func('rb_time_interval')
 have_func('rb_wait_for_single_fd')
+have_func('rb_str_subseq')
 
 create_makefile('kgio_ext')
diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c
index 51d2d16..9924743 100644
--- a/ext/kgio/read_write.c
+++ b/ext/kgio/read_write.c
@@ -4,6 +4,9 @@
 static VALUE sym_wait_readable, sym_wait_writable;
 static VALUE eErrno_EPIPE, eErrno_ECONNRESET;
 static ID id_set_backtrace;
+#ifndef HAVE_RB_STR_SUBSEQ
+#define rb_str_subseq rb_str_substr
+#endif
 
 /*
  * we know MSG_DONTWAIT works properly on all stream sockets under Linux
@@ -338,7 +341,7 @@ done:
 				a->ptr = RSTRING_PTR(a->buf) + written;
 				return -1;
 			} else if (written > 0) {
-				a->buf = rb_str_new(a->ptr, a->len);
+				a->buf = rb_str_subseq(a->buf, written, a->len);
 			} else {
 				a->buf = sym_wait_writable;
 			}
-- 
1.7.9.5



  reply	other threads:[~2012-05-30 13:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 13:56 [PATCH 1/3] Fix UnixClientReadServerWrite test class name Sokolov Yura 'funny-falcon
2012-05-30 13:56 ` Sokolov Yura 'funny-falcon [this message]
2012-05-30 18:57   ` [PATCH 2/3] use rb_str_subseq for tail string on write Eric Wong
2012-05-30 19:29     ` Юрий Соколов
2012-05-30 13:56 ` [PATCH 3/3] add `#kgio_writev` and `#kgio_trywritev` Sokolov Yura 'funny-falcon
2012-05-30 19:55   ` Юрий Соколов
2012-05-30 20:38     ` Eric Wong
2012-05-31  6:16       ` Юрий Соколов
2012-05-31 21:10         ` Eric Wong
2012-05-30 20:39   ` Eric Wong
2012-05-31  6:26     ` Юрий Соколов
2012-05-31 21:14       ` Eric Wong
2012-05-31 21:56         ` Eric Wong
2012-05-31  9:00     ` Sokolov Yura 'funny-falcon
2012-05-31 21:19       ` Eric Wong
2012-06-01  6:14         ` Юрий Соколов
2012-06-01  7:55           ` Eric Wong
2012-06-01  9:42             ` [PATCH] " Sokolov Yura 'funny-falcon
2012-06-01 19:20               ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/kgio/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338386216-14568-2-git-send-email-funny.falcon@gmail.com \
    --to=funny.falcon@gmail.com \
    --cc=kgio@librelist.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).