diff options
author | Neil Jerram <neil@ossau.uklinux.net> | 2008-09-15 00:25:25 +0100 |
---|---|---|
committer | Neil Jerram <neil@ossau.uklinux.net> | 2008-09-15 18:52:51 +0100 |
commit | b5cb4464ca4e23d077a9777bbc17835feb0f4374 (patch) | |
tree | 07e03fdfbb0b742031192ed1305d89e78fffc391 /libguile/srfi-4.c | |
parent | aa51e98ac5bcb36298741c9948039ac253e86c35 (diff) | |
download | guile-b5cb4464ca4e23d077a9777bbc17835feb0f4374.tar.gz |
Make multi-byte reads on unbuffered ports more efficient.
Idea and original patch were by Ludovic Courtès, this is Neil Jerram's
reworking of it.
* libguile/srfi-4.c (scm_uniform_vector_read_x): Use scm_c_read,
instead of equivalent code here.
* libguile/ports.c (scm_fill_input): Add assertion that read
buffer is empty when called.
(port_and_swap_buffer, swap_buffer): New, for...
(scm_c_read): Use caller's buffer for reading, to avoid making N
1-byte low-level read calls, in the case where the port is
unbuffered (or has a very small buffer).
Diffstat (limited to 'libguile/srfi-4.c')
-rw-r--r-- | libguile/srfi-4.c | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/libguile/srfi-4.c b/libguile/srfi-4.c index 3aedbebe7..b0e052ac3 100644 --- a/libguile/srfi-4.c +++ b/libguile/srfi-4.c @@ -886,38 +886,11 @@ SCM_DEFINE (scm_uniform_vector_read_x, "uniform-vector-read!", 1, 3, 0, if (SCM_NIMP (port_or_fd)) { - scm_t_port *pt = SCM_PTAB_ENTRY (port_or_fd); - - if (pt->rw_active == SCM_PORT_WRITE) - scm_flush (port_or_fd); - ans = cend - cstart; - while (remaining > 0) - { - if (pt->read_pos < pt->read_end) - { - size_t to_copy = min (pt->read_end - pt->read_pos, - remaining); - - memcpy (base + off, pt->read_pos, to_copy); - pt->read_pos += to_copy; - remaining -= to_copy; - off += to_copy; - } - else - { - if (scm_fill_input (port_or_fd) == EOF) - { - if (remaining % sz != 0) - SCM_MISC_ERROR ("unexpected EOF", SCM_EOL); - ans -= remaining / sz; - break; - } - } - } - - if (pt->rw_random) - pt->rw_active = SCM_PORT_READ; + remaining -= scm_c_read (port_or_fd, base + off, remaining); + if (remaining % sz != 0) + SCM_MISC_ERROR ("unexpected EOF", SCM_EOL); + ans -= remaining / sz; } else /* file descriptor. */ { |