[Python-checkins] python/dist/src/Lib calendar.py,1.34,1.35

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sat Nov 13 17:18:34 CET 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1137/Lib
Modified Files:
	calendar.py 
Log Message:
SF bug 1065388: calendar day/month name lookup too slow
__getitem__() methods: compute only the new spellings needed to satisfy
the given indexing object. This is purely an optimization (it should
have no effect on visible semantics).
Index: calendar.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/calendar.py,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- calendar.py	7 Jun 2004 03:47:06 -0000	1.34
+++ calendar.py	13 Nov 2004 16:18:31 -0000	1.35
@@ -28,27 +28,37 @@
 # fresh on each call, in case the user changes locale between calls.
 
 class _localized_month:
+
+ _months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
+ _months.insert(0, lambda x: "")
+
 def __init__(self, format):
 self.format = format
 
 def __getitem__(self, i):
- data = [datetime.date(2001, j, 1).strftime(self.format)
- for j in range(1, 13)]
- data.insert(0, "")
- return data[i]
+ funcs = self._months[i]
+ if isinstance(i, slice):
+ return [f(self.format) for f in funcs]
+ else:
+ return funcs(self.format)
 
 def __len__(self):
 return 13
 
 class _localized_day:
+
+ # January 1, 2001, was a Monday.
+ _days = [datetime.date(2001, 1, i+1).strftime for i in range(7)]
+
 def __init__(self, format):
 self.format = format
 
 def __getitem__(self, i):
- # January 1, 2001, was a Monday.
- data = [datetime.date(2001, 1, j+1).strftime(self.format)
- for j in range(7)]
- return data[i]
+ funcs = self._days[i]
+ if isinstance(i, slice):
+ return [f(self.format) for f in funcs]
+ else:
+ return funcs(self.format)
 
 def __len__(self):
 return 7


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /