summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-12-20 01:31:27 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-12-20 01:31:27 (GMT)
commit328fff72149a896141209b57b577b4dc57ea5d90 (patch)
treed78d51ecd4cfa4cb574794b2e241d193035e4588 /Modules
parentd0e2926d2a10ff3414b3d9177034728c1a074cd1 (diff)
downloadcpython-328fff72149a896141209b57b577b4dc57ea5d90.zip
cpython-328fff72149a896141209b57b577b4dc57ea5d90.tar.gz
cpython-328fff72149a896141209b57b577b4dc57ea5d90.tar.bz2
format_utcoffset(): The natural type of the buflen arg is size_t, so
used that. wrap_strftime(): Removed the most irritating uses of buf. TestDate.test_ordinal_conversions(): The C implementation is fast enough that we can afford to check the endpoints of every year. Also added tm_yday tests at the endpoints.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 3aab3ad..6dff659 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -812,7 +812,7 @@ format_ctime(PyDateTime_Date *date,
* bogus, an appropriate exception is set and -1 is returned.
*/
static int
-format_utcoffset(char *buf, int buflen, const char *sep,
+format_utcoffset(char *buf, size_t buflen, const char *sep,
PyObject *tzinfo, PyObject *tzinfoarg)
{
int offset;
@@ -863,13 +863,12 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple)
char *ptoappend; /* pointer to string to append to output buffer */
int ntoappend; /* # of bytes to append to output buffer */
- char buf[100]; /* scratch buffer */
-
assert(object && format && timetuple);
assert(PyString_Check(format));
/* Scan the input format, looking for %z and %Z escapes, building
- * a new format.
+ * a new format. Since computing the replacements for those codes
+ * is expensive, don't unless they're actually used.
*/
totalnew = PyString_Size(format); /* realistic if no %z/%Z */
newfmt = PyString_FromStringAndSize(NULL, totalnew);
@@ -880,8 +879,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple)
pin = PyString_AsString(format);
while ((ch = *pin++) != '\0') {
if (ch != '%') {
- buf[0] = ch;
- ptoappend = buf;
+ ptoappend = pin - 1;
ntoappend = 1;
}
else if ((ch = *pin++) == '\0') {
@@ -894,12 +892,13 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple)
else if (ch == 'z') {
if (zreplacement == NULL) {
/* format utcoffset */
+ char buf[100];
PyObject *tzinfo = get_tzinfo_member(object);
zreplacement = PyString_FromString("");
if (zreplacement == NULL) goto Done;
if (tzinfo != Py_None && tzinfo != NULL) {
if (format_utcoffset(buf,
- (int)sizeof(buf),
+ sizeof(buf),
"",
tzinfo,
object) < 0)
@@ -948,9 +947,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple)
ntoappend = PyString_Size(Zreplacement);
}
else {
- buf[0] = '%';
- buf[1] = ch;
- ptoappend = buf;
+ /* percent followed by neither z nor Z */
+ ptoappend = pin - 2;
ntoappend = 2;
}