[Python-checkins] CVS: python/dist/src/Objects longobject.c,1.77,1.78

Tim Peters tim_one@users.sourceforge.net
Wed, 13 Jun 2001 14:01:29 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv19167/python/dist/src/Objects

Modified Files:
	longobject.c 
Log Message:
_PyLong_AsByteArray:  Don't do the "delicate overflow" check unless it's
truly needed; usually saves a little time, but no change in semantics.


Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -r1.77 -r1.78
*** longobject.c	2001/06/13 20:50:08	1.77
--- longobject.c	2001/06/13 21:01:27	1.78
***************
*** 425,440 ****
  		p += pincr;
  	}
! 
! 	/* Fill remaining bytes with copies of the sign bit. */
! 	for ( ; j < n; ++j, p += pincr)
! 		*p = (unsigned char)(do_twos_comp ? 0xff : 0);
! 
! 	/* Check for delicate overflow (not enough room for the sign bit). */
! 	if (j > 0 && is_signed) {
  		unsigned char msb = *(p - pincr);
! 		int sign_bit_set = (msb & 0x80) != 0;
! 		if (sign_bit_set != do_twos_comp)
  			goto Overflow;
  	}
  	return 0;
  
--- 425,449 ----
  		p += pincr;
  	}
! 	else if (j == n && n > 0 && is_signed) {
! 		/* The main loop filled the byte array exactly, so the code
! 		   just above didn't get to ensure there's a sign bit, and the
! 		   loop below wouldn't add one either.  Make sure a sign bit
! 		   exists. */
  		unsigned char msb = *(p - pincr);
! 		int sign_bit_set = msb >= 0x80;
! 		assert(accumbits == 0);
! 		if (sign_bit_set == do_twos_comp)
! 			return 0;
! 		else
  			goto Overflow;
  	}
+ 
+ 	/* Fill remaining bytes with copies of the sign bit. */
+ 	{
+ 		unsigned char signbyte = do_twos_comp ? 0xffU : 0U;
+ 		for ( ; j < n; ++j, p += pincr)
+ 			*p = signbyte;
+ 	}
+ 
  	return 0;