[Python-checkins] CVS: python/nondist/sandbox/datetime datetime.py,1.48,1.49

Tim Peters tim_one@users.sourceforge.net
Tue, 05 Mar 2002 00:30:33 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv14634

Modified Files:
	datetime.py 
Log Message:
_ord2ymd():  Cheaper way to estimate the month, with an addition and a
shift, replacing an addition, a division, and a min().  Amazingly, in both
leap and non-leap years, this needs to take the "if" (correction) branch
exactly as many times as the more expensive method (across all possible
values for n).


Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** datetime.py	5 Mar 2002 04:15:53 -0000	1.48
--- datetime.py	5 Mar 2002 08:30:31 -0000	1.49
***************
*** 133,137 ****
      leapyear = n1 == 3 and (n4 != 24 or n100 == 3)
      assert leapyear == _is_leap(year)
!     month = min(n//29 + 1, 12)
      preceding = _DAYS_BEFORE_MONTH[month] + (month > 2 and leapyear)
      if preceding > n:  # estimate is too large
--- 133,137 ----
      leapyear = n1 == 3 and (n4 != 24 or n100 == 3)
      assert leapyear == _is_leap(year)
!     month = (n + 50) >> 5
      preceding = _DAYS_BEFORE_MONTH[month] + (month > 2 and leapyear)
      if preceding > n:  # estimate is too large