From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Move slow path out of 'scm_get_byte_or_eof' et al Date: Tue, 02 Apr 2013 05:59:57 -0400 Message-ID: <87a9ph1cde.fsf@tines.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1364896833 23452 80.91.229.3 (2 Apr 2013 10:00:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Apr 2013 10:00:33 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Apr 02 12:01:00 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UMy1T-00077H-8G for guile-devel@m.gmane.org; Tue, 02 Apr 2013 12:00:59 +0200 Original-Received: from localhost ([::1]:47053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMy14-0001Bz-N6 for guile-devel@m.gmane.org; Tue, 02 Apr 2013 06:00:34 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:44099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMy0u-00019I-TE for guile-devel@gnu.org; Tue, 02 Apr 2013 06:00:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMy0t-0006sN-C1 for guile-devel@gnu.org; Tue, 02 Apr 2013 06:00:24 -0400 Original-Received: from world.peace.net ([96.39.62.75]:57828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMy0t-0006pz-7Z for guile-devel@gnu.org; Tue, 02 Apr 2013 06:00:23 -0400 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UMy0a-0006Mg-Jy; Tue, 02 Apr 2013 06:00:04 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16102 Archived-At: --=-=-= Content-Type: text/plain Andy suggested this. Okay to push to stable-2.0? Mark --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Move-slow-path-out-of-scm_get_byte_or_eof-et-al.patch Content-Description: [PATCH] Move slow path out of 'scm_get_byte_or_eof' et al >From 0b70eba61ee26654f442199e7cc49838c5b0030e Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Tue, 2 Apr 2013 05:33:24 -0400 Subject: [PATCH] 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. --- libguile/inline.h | 44 ++++++++++---------------------------------- libguile/ports.c | 41 +++++++++++++++++++++++++++++++++++++++++ libguile/ports.h | 2 ++ 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/libguile/inline.h b/libguile/inline.h index 88ba7f7..17d8a0c 100644 --- a/libguile/inline.h +++ b/libguile/inline.h @@ -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 diff --git a/libguile/ports.c b/libguile/ports.c index becdbed..76ec83f 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -1439,6 +1439,47 @@ scm_fill_input (SCM port) return scm_ptobs[SCM_PTOBNUM (port)].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_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_fill_input (port) == EOF)) + return EOF; + } + + return *pt->read_pos; +} /* scm_lfwrite * diff --git a/libguile/ports.h b/libguile/ports.h index 53d5081..54bf595 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -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); -- 1.7.10.4 --=-=-=--