1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-26 05:00:28 +02:00

peek-u8 correctness and speed refactor

* libguile/ports-internal.h (scm_port_buffer_size): Verify that the
  bytevector field is a bytevector, in anticipation of Schemification.
  (scm_port_buffer_can_take, scm_port_buffer_can_put)
  (scm_port_buffer_can_putback): Enforce invariants on cur and end
  here.
  (scm_port_buffer_did_take, scm_port_buffer_did_put): Relax to not call
  other functions.
* libguile/ports.h (scm_get_byte_or_eof_unlocked)
  (scm_peek_byte_or_eof_unlocked): Refactor to call no functions on the
  fast path.
This commit is contained in:
Andy Wingo 2016-04-19 22:58:33 +02:00
parent ffb4347d53
commit bb6edc5a35
2 changed files with 47 additions and 13 deletions

View file

@ -429,13 +429,15 @@ SCM_INLINE_IMPLEMENTATION int
scm_get_byte_or_eof_unlocked (SCM port)
{
scm_t_port_buffer *buf = SCM_PTAB_ENTRY (port)->read_buf;
size_t cur;
size_t cur = SCM_I_INUM (buf->cur);
cur = scm_to_size_t (buf->cur);
if (SCM_LIKELY (cur < scm_to_size_t (buf->end)))
if (SCM_LIKELY (SCM_I_INUMP (buf->cur))
&& SCM_LIKELY (SCM_I_INUMP (buf->end))
&& SCM_LIKELY (cur < SCM_I_INUM (buf->end))
&& SCM_LIKELY (cur < SCM_BYTEVECTOR_LENGTH (buf->bytevector)))
{
scm_t_uint8 ret = SCM_BYTEVECTOR_CONTENTS (buf->bytevector)[cur];
buf->cur = scm_from_size_t (cur + 1);
buf->cur = SCM_I_MAKINUM (cur + 1);
return ret;
}
@ -459,10 +461,12 @@ SCM_INLINE_IMPLEMENTATION int
scm_peek_byte_or_eof_unlocked (SCM port)
{
scm_t_port_buffer *buf = SCM_PTAB_ENTRY (port)->read_buf;
size_t cur;
size_t cur = SCM_I_INUM (buf->cur);
cur = scm_to_size_t (buf->cur);
if (SCM_LIKELY (cur < scm_to_size_t (buf->end)))
if (SCM_LIKELY (SCM_I_INUMP (buf->cur))
&& SCM_LIKELY (SCM_I_INUMP (buf->end))
&& SCM_LIKELY (cur < SCM_I_INUM (buf->end))
&& SCM_LIKELY (cur < SCM_BYTEVECTOR_LENGTH (buf->bytevector)))
{
scm_t_uint8 ret = SCM_BYTEVECTOR_CONTENTS (buf->bytevector)[cur];
return ret;