small optimization in iconv/skeleton.c

Bruno Haible haible@ilog.fr
Mon Sep 11 09:10:00 GMT 2000


The test
        if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION)
            || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION))
is certain to evaluate to 1 if MAX_NEEDED_FROM > 1 and MAX_NEEDED_TO > 1
are both true. Here is a patch to optimize this. It elimimates a redundant
runtime test which gcc-2.95.2, even with "-O2", does not completely eliminate.


2000-09-10  Bruno Haible <haible@clisp.cons.org>

	* iconv/skeleton.c (FUNCTION_NAME): Optimize an `if' if
	MAX_NEEDED_FROM > 1 && MAX_NEEDED_TO > 1.

*** glibc-20000831/iconv/skeleton.c.bak	Sun Sep 10 01:16:59 2000
--- glibc-20000831/iconv/skeleton.c	Sun Sep 10 15:44:19 2000
***************
*** 339,345 ****
        /* If the function is used to implement the mb*towc*() or wc*tomb*()
  	 functions we must test whether any bytes from the last call are
  	 stored in the `state' object.  */
!       if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION)
  	   || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION))
  	  && consume_incomplete && (data->__statep->__count & 7) != 0)
  	{
--- 344,351 ----
        /* If the function is used to implement the mb*towc*() or wc*tomb*()
  	 functions we must test whether any bytes from the last call are
  	 stored in the `state' object.  */
!       if (((MAX_NEEDED_FROM > 1 && MAX_NEEDED_TO > 1)
! 	   || (MAX_NEEDED_FROM > 1 && FROM_DIRECTION)
  	   || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION))
  	  && consume_incomplete && (data->__statep->__count & 7) != 0)
  	{
***************
*** 540,546 ****
        /* If we are supposed to consume all character store now all of the
  	 remaining characters in the `state' object.  */
  #if MAX_NEEDED_FROM > 1 || MAX_NEEDED_TO > 1
!       if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION)
  	   || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION))
  	  && __builtin_expect (consume_incomplete, 0)
  	  && status == __GCONV_INCOMPLETE_INPUT)
--- 567,574 ----
        /* If we are supposed to consume all character store now all of the
  	 remaining characters in the `state' object.  */
  #if MAX_NEEDED_FROM > 1 || MAX_NEEDED_TO > 1
!       if (((MAX_NEEDED_FROM > 1 && MAX_NEEDED_TO > 1)
! 	   || (MAX_NEEDED_FROM > 1 && FROM_DIRECTION)
  	   || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION))
  	  && __builtin_expect (consume_incomplete, 0)
  	  && status == __GCONV_INCOMPLETE_INPUT)


More information about the Libc-alpha mailing list