1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 13:30:26 +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:
Mark H Weaver 2013-04-02 05:33:24 -04:00
parent 187fa0b9e7
commit 8a2b596579
3 changed files with 54 additions and 34 deletions

View file

@ -96,50 +96,26 @@ scm_is_string (SCM x)
SCM_INLINE_IMPLEMENTATION int
scm_get_byte_or_eof (SCM port)
{
int c;
scm_t_port *pt = SCM_PTAB_ENTRY (port);
if (pt->rw_active == SCM_PORT_WRITE)
/* may be marginally faster than calling scm_flush. */
scm_ptobs[SCM_PTOBNUM (port)].flush (port);
if (pt->rw_random)
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;
if (SCM_LIKELY ((pt->rw_active == SCM_PORT_READ || !pt->rw_random)
&& pt->read_pos < pt->read_end))
return *pt->read_pos++;
else
return scm_i_get_byte_or_eof (port);
}
/* Like `scm_get_byte_or_eof' but does not change PORT's `read_pos'. */
SCM_INLINE_IMPLEMENTATION int
scm_peek_byte_or_eof (SCM port)
{
int c;
scm_t_port *pt = SCM_PTAB_ENTRY (port);
if (pt->rw_active == SCM_PORT_WRITE)
/* may be marginally faster than calling scm_flush. */
scm_ptobs[SCM_PTOBNUM (port)].flush (port);
if (pt->rw_random)
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;
if (SCM_LIKELY ((pt->rw_active == SCM_PORT_READ || !pt->rw_random)
&& pt->read_pos < pt->read_end))
return *pt->read_pos;
else
return scm_i_peek_byte_or_eof (port);
}
SCM_INLINE_IMPLEMENTATION void

View file

@ -1445,6 +1445,48 @@ scm_fill_input (SCM 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
*

View file

@ -328,6 +328,8 @@ scm_i_default_port_conversion_handler (void);
/* Use HANDLER as the default conversion strategy for future ports. */
SCM_INTERNAL void
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_set_port_conversion_strategy_x (SCM port, SCM behavior);