mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 21:40:33 +02:00
Move slow path out of 'scm_get_byte_or_eof' et al.
Suggested by Andy Wingo. * libguile/inline.h (scm_get_byte_or_eof, scm_peek_byte_or_eof): Keep only the fast path here, with fallback to 'scm_i_get_byte_or_eof' and 'scm_i_peek_byte_or_eof'. * libguile/ports.c (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): New internal functions. * libguile/ports.h (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): Add prototypes.
This commit is contained in:
parent
187fa0b9e7
commit
8a2b596579
3 changed files with 54 additions and 34 deletions
|
@ -96,50 +96,26 @@ scm_is_string (SCM x)
|
||||||
SCM_INLINE_IMPLEMENTATION int
|
SCM_INLINE_IMPLEMENTATION int
|
||||||
scm_get_byte_or_eof (SCM port)
|
scm_get_byte_or_eof (SCM port)
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
|
|
||||||
if (pt->rw_active == SCM_PORT_WRITE)
|
if (SCM_LIKELY ((pt->rw_active == SCM_PORT_READ || !pt->rw_random)
|
||||||
/* may be marginally faster than calling scm_flush. */
|
&& pt->read_pos < pt->read_end))
|
||||||
scm_ptobs[SCM_PTOBNUM (port)].flush (port);
|
return *pt->read_pos++;
|
||||||
|
else
|
||||||
if (pt->rw_random)
|
return scm_i_get_byte_or_eof (port);
|
||||||
pt->rw_active = SCM_PORT_READ;
|
|
||||||
|
|
||||||
if (pt->read_pos >= pt->read_end)
|
|
||||||
{
|
|
||||||
if (SCM_UNLIKELY (scm_fill_input (port) == EOF))
|
|
||||||
return EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = *(pt->read_pos++);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like `scm_get_byte_or_eof' but does not change PORT's `read_pos'. */
|
/* Like `scm_get_byte_or_eof' but does not change PORT's `read_pos'. */
|
||||||
SCM_INLINE_IMPLEMENTATION int
|
SCM_INLINE_IMPLEMENTATION int
|
||||||
scm_peek_byte_or_eof (SCM port)
|
scm_peek_byte_or_eof (SCM port)
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
|
|
||||||
if (pt->rw_active == SCM_PORT_WRITE)
|
if (SCM_LIKELY ((pt->rw_active == SCM_PORT_READ || !pt->rw_random)
|
||||||
/* may be marginally faster than calling scm_flush. */
|
&& pt->read_pos < pt->read_end))
|
||||||
scm_ptobs[SCM_PTOBNUM (port)].flush (port);
|
return *pt->read_pos;
|
||||||
|
else
|
||||||
if (pt->rw_random)
|
return scm_i_peek_byte_or_eof (port);
|
||||||
pt->rw_active = SCM_PORT_READ;
|
|
||||||
|
|
||||||
if (pt->read_pos >= pt->read_end)
|
|
||||||
{
|
|
||||||
if (SCM_UNLIKELY (scm_fill_input (port) == EOF))
|
|
||||||
return EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = *pt->read_pos;
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM_INLINE_IMPLEMENTATION void
|
SCM_INLINE_IMPLEMENTATION void
|
||||||
|
|
|
@ -1445,6 +1445,48 @@ scm_fill_input (SCM port)
|
||||||
return scm_i_fill_input (port);
|
return scm_i_fill_input (port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Slow-path fallback for 'scm_get_byte_or_eof' in inline.h */
|
||||||
|
int
|
||||||
|
scm_i_get_byte_or_eof (SCM port)
|
||||||
|
{
|
||||||
|
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
|
|
||||||
|
if (pt->rw_active == SCM_PORT_WRITE)
|
||||||
|
scm_flush (port);
|
||||||
|
|
||||||
|
if (pt->rw_random)
|
||||||
|
pt->rw_active = SCM_PORT_READ;
|
||||||
|
|
||||||
|
if (pt->read_pos >= pt->read_end)
|
||||||
|
{
|
||||||
|
if (SCM_UNLIKELY (scm_i_fill_input (port) == EOF))
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *pt->read_pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Slow-path fallback for 'scm_peek_byte_or_eof' in inline.h */
|
||||||
|
int
|
||||||
|
scm_i_peek_byte_or_eof (SCM port)
|
||||||
|
{
|
||||||
|
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
|
|
||||||
|
if (pt->rw_active == SCM_PORT_WRITE)
|
||||||
|
scm_flush (port);
|
||||||
|
|
||||||
|
if (pt->rw_random)
|
||||||
|
pt->rw_active = SCM_PORT_READ;
|
||||||
|
|
||||||
|
if (pt->read_pos >= pt->read_end)
|
||||||
|
{
|
||||||
|
if (SCM_UNLIKELY (scm_i_fill_input (port) == EOF))
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *pt->read_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* scm_lfwrite
|
/* scm_lfwrite
|
||||||
*
|
*
|
||||||
|
|
|
@ -328,6 +328,8 @@ scm_i_default_port_conversion_handler (void);
|
||||||
/* Use HANDLER as the default conversion strategy for future ports. */
|
/* Use HANDLER as the default conversion strategy for future ports. */
|
||||||
SCM_INTERNAL void
|
SCM_INTERNAL void
|
||||||
scm_i_set_default_port_conversion_handler (scm_t_string_failed_conversion_handler);
|
scm_i_set_default_port_conversion_handler (scm_t_string_failed_conversion_handler);
|
||||||
|
SCM_INTERNAL int scm_i_get_byte_or_eof (SCM port);
|
||||||
|
SCM_INTERNAL int scm_i_peek_byte_or_eof (SCM port);
|
||||||
|
|
||||||
SCM_API SCM scm_port_conversion_strategy (SCM port);
|
SCM_API SCM scm_port_conversion_strategy (SCM port);
|
||||||
SCM_API SCM scm_set_port_conversion_strategy_x (SCM port, SCM behavior);
|
SCM_API SCM scm_set_port_conversion_strategy_x (SCM port, SCM behavior);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue