From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] io: quick-n-dirty try to use locktmp to avoid alloc in write
Date: Thu, 29 Dec 2016 00:57:01 +0000 [thread overview]
Message-ID: <20161229005701.9712-1-e@80x24.org> (raw)
This causs failures with TestIO#test_threaded_flush
---
io.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/io.c b/io.c
index 1074689560..bee2435fad 100644
--- a/io.c
+++ b/io.c
@@ -1222,6 +1222,7 @@ struct binwrite_arg {
VALUE str;
const char *ptr;
long length;
+ int nosync;
};
struct write_arg {
@@ -1419,10 +1420,20 @@ do_writeconv(VALUE str, rb_io_t *fptr, int *converted)
return str;
}
+static VALUE
+binwrite_call(VALUE arg)
+{
+ struct binwrite_arg *p = (struct binwrite_arg*)arg;
+
+ p->length = io_binwrite(p->str, p->ptr, p->length, p->fptr, p->nosync);
+ return Qundef;
+}
+
static long
io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
{
int converted = 0;
+ struct binwrite_arg arg;
#ifdef _WIN32
if (fptr->mode & FMODE_TTY) {
long len = rb_w32_write_console(str, fptr->fd);
@@ -1432,11 +1443,19 @@ io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
str = do_writeconv(str, fptr, &converted);
if (converted)
OBJ_FREEZE(str);
- else
- str = rb_str_new_frozen(str);
+ if (OBJ_FROZEN(str))
+ return io_binwrite(str, RSTRING_PTR(str), RSTRING_LEN(str),
+ fptr, nosync);
+
+ arg.fptr = fptr;
+ arg.str = str;
+ arg.ptr = RSTRING_PTR(str);
+ arg.length = RSTRING_LEN(str);
+ arg.nosync = nosync;
+
+ rb_str_locktmp_ensure(str, binwrite_call, (VALUE)&arg);
- return io_binwrite(str, RSTRING_PTR(str), RSTRING_LEN(str),
- fptr, nosync);
+ return arg.length;
}
ssize_t
--
EW
reply other threads:[~2016-12-29 0:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161229005701.9712-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/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.
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).