Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r61991:68cf7a8984a1 Date: 2013-03-04 02:12 -0500 http://bitbucket.org/pypy/pypy/changeset/68cf7a8984a1/
Log: optimize datetime.strftime %f like others diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -176,6 +176,7 @@ raise ValueError("year=%d is before 1900; the datetime strftime() " "methods require year >= 1900" % year) # Don't call _utcoffset() or tzname() unless actually needed. + freplace = None # the string to use for %f zreplace = None # the string to use for %z Zreplace = None # the string to use for %Z @@ -190,7 +191,12 @@ if i < n: ch = format[i] i += 1 - if ch == 'z': + if ch == 'f': + if freplace is None: + freplace = '%06d' % getattr(object, + 'microsecond', 0) + newformat.append(freplace) + elif ch == 'z': if zreplace is None: zreplace = "" if hasattr(object, "_utcoffset"): @@ -213,11 +219,6 @@ # strftime is going to have at this: escape % Zreplace = s.replace('%', '%%') newformat.append(Zreplace) - elif ch == 'f': - if isinstance(object, (time, datetime)): - newformat.append('%06d' % object.microsecond) - else: - newformat.append('000000') else: push('%') push(ch) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit