[Checkins] SVN: DateTime/trunk/ Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon` and `_pmon` in memory for every instance but look them up dynamically based on `_dayoffset` and `_month`. This saves another 150 bytes of memory per DateTime instance.
Hanno Schlichting
hannosch at hannosch.eu
Sun May 8 08:32:20 EDT 2011
Log message for revision 121590:
Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon` and `_pmon` in memory for every instance but look them up dynamically based on `_dayoffset` and `_month`. This saves another 150 bytes of memory per DateTime instance.
Changed:
U DateTime/trunk/CHANGES.txt
U DateTime/trunk/src/DateTime/DateTime.py
-=-
Modified: DateTime/trunk/CHANGES.txt
===================================================================
--- DateTime/trunk/CHANGES.txt 2011-05-08 12:25:42 UTC (rev 121589)
+++ DateTime/trunk/CHANGES.txt 2011-05-08 12:32:20 UTC (rev 121590)
@@ -4,7 +4,9 @@
3.0 (unreleased)
----------------
-- Avoid storing `_aday`, `_fday` and `_pday` in memory.
+- Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon` and `_pmon` in
+ memory for every instance but look them up dynamically based on `_dayoffset`
+ and `_month`. This saves another 150 bytes of memory per DateTime instance.
- Moved various internal parsing related class variables to module constants.
Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py 2011-05-08 12:25:42 UTC (rev 121589)
+++ DateTime/trunk/src/DateTime/DateTime.py 2011-05-08 12:32:20 UTC (rev 121590)
@@ -417,9 +417,6 @@
'_pm',
'_pmhour',
'_dayoffset',
- '_fmon',
- '_amon',
- '_pmon',
'_year',
'_month',
'_day',
@@ -835,8 +832,6 @@
self._pmhour=hr or 12
self._pm= (hr==12) and 'pm' or 'am'
self._dayoffset = int((_julianday(yr,mo,dy) + 2L) % 7)
- self._fmon, self._amon, self._pmon = \
- _MONTHS[mo], _MONTHS_A[mo], _MONTHS_P[mo]
# Round to nearest microsecond in platform-independent way. You
# cannot rely on C sprintf (Python '%') formatting to round
# consistently; doing it ourselves ensures that all but truly
@@ -1355,10 +1350,18 @@
"""Return the month of the object as an integer."""
return self._month
+ @property
+ def _fmon(self):
+ return _MONTHS[self._month]
+
def Month(self):
"""Return the full month name."""
return self._fmon
+ @property
+ def _amon(self):
+ return _MONTHS_A[self._month]
+
def aMonth(self):
"""Return the abreviated month name."""
return self._amon
@@ -1367,6 +1370,10 @@
"""Compatibility: see aMonth."""
return self._amon
+ @property
+ def _pmon(self):
+ return _MONTHS_P[self._month]
+
def pMonth(self):
"""Return the abreviated (with period) month name."""
return self._pmon
More information about the checkins
mailing list