Skip to content

Commit 46d83e3

Browse files
Benedikts suggestions
1 parent 1fa3270 commit 46d83e3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Implement a fast path for date types in :func:`datetime.date.today`
1+
Implement a fast path for :class:`datetime.date` objects in :func:`datetime.date.today`
2+
which results in a 5x performance gain while proper subclasses retain their
3+
previous performance.

Modules/_datetimemodule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,25 +3265,26 @@ date_today(PyObject *cls, PyObject *Py_UNUSED(dummy))
32653265
time_t t;
32663266
time(&t);
32673267

3268-
if (_PyTime_localtime(t, &tm) != 0)
3268+
if (_PyTime_localtime(t, &tm) != 0) {
32693269
return NULL;
3270+
}
32703271

32713272
return new_date_ex(tm.tm_year + 1900,
32723273
tm.tm_mon + 1,
32733274
tm.tm_mday,
32743275
(PyTypeObject*)cls);
3275-
} else {
3276+
}
3277+
else {
32763278
PyObject *time;
32773279
PyObject *result;
32783280
time = time_time();
3279-
if (time == NULL)
3281+
if (time == NULL) {
32803282
return NULL;
3283+
}
32813284

32823285
/* Note well: today() is a class method, so this may not call
32833286
* date.fromtimestamp. For example, it may call
3284-
* datetime.fromtimestamp. That's why we need all the accuracy
3285-
* time.time() delivers; if someone were gonzo about optimization,
3286-
* date.today() could get away with plain C time().
3287+
* datetime.fromtimestamp.
32873288
*/
32883289
result = PyObject_CallMethodOneArg(cls, &_Py_ID(fromtimestamp), time);
32893290
Py_DECREF(time);

0 commit comments

Comments
 (0)