Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1cb7b91
Make timedelta.__repr__ more informative.
musically-ut May 7, 2017
84241de
Make C impl of timedelta.__repr__ more informative
musically-ut May 7, 2017
2e61096
Fix tests.
musically-ut May 7, 2017
e6970c8
Add more tests.
musically-ut Jun 25, 2017
f5dd914
Do not show args which are 0.
musically-ut Jun 27, 2017
e1c33ab
Fix bug to run tests on both C and Python code.
musically-ut Jun 27, 2017
345557b
Use append/join instead of concatenating strings.
musically-ut Jun 27, 2017
e79d223
Remove unsed tests.
musically-ut Jun 27, 2017
312b81b
Use append/join in C implementation.
musically-ut Jun 27, 2017
1ca30ee
Remove documentation of `repr`.
musically-ut Jun 27, 2017
f643b40
Do stricter reference management, remove refleaks.
musically-ut Jun 27, 2017
194bfde
Inline simple expression.
musically-ut Jun 27, 2017
a40e0c1
Add checks for C-API failures.
musically-ut Jun 27, 2017
69213f7
Make DECREFs more concise.
musically-ut Jun 27, 2017
c939f81
Add more tests.
musically-ut Jun 29, 2017
9e7bd21
Update documentation for repr.
musically-ut Jun 29, 2017
863485c
timedelta(seconds=0) -> timedelta(0)
musically-ut Jun 29, 2017
5d5a92e
Make the code more DRY.
musically-ut Jun 29, 2017
16516a4
Remove empty lines and use idiomatic methods.
musically-ut Jun 29, 2017
2fa3e20
Revert white-space regression in documentation.
musically-ut Jun 29, 2017
10817a8
Update ACKS and NEWS.d.
musically-ut Jun 30, 2017
e26ab32
Use PyUnicode_* instead of PyList_*.
musically-ut Jun 30, 2017
83ea587
Make the invariant in case of repr explicit.
musically-ut Jun 30, 2017
23eb9ec
Place name at the correct alphabetical position.
musically-ut Jul 6, 2017
ae93f8e
Update documentation.
musically-ut Jul 6, 2017
3d327f4
char * -> const char*
musically-ut Jul 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use append/join in C implementation.
  • Loading branch information
musically-ut committed Jul 25, 2017
commit 312b81b6cde006e0ded48cd145898a66a773c5ee
25 changes: 9 additions & 16 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,33 +2284,26 @@ delta_bool(PyDateTime_Delta *self)
static PyObject *
delta_repr(PyDateTime_Delta *self)
{
char days[64] = "", seconds[64] = "", microseconds[64] = "";
PyObject *args = PyList_New(0);

if (GET_TD_DAYS(self) != 0) {
sprintf(days, "days=%d", GET_TD_DAYS(self));
PyList_Append(args, PyUnicode_FromFormat("days=%d", GET_TD_DAYS(self)));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can decref days here. This will simplify the cases for seconds and microseconds.


if (GET_TD_SECONDS(self) != 0 ||
(GET_TD_DAYS(self) == 0 && GET_TD_MICROSECONDS(self) == 0)) {
if (strlen(days) == 0) {
sprintf(seconds, "seconds=%d", GET_TD_SECONDS(self));
} else {
sprintf(seconds, ", seconds=%d", GET_TD_SECONDS(self));
}
PyList_Append(args, PyUnicode_FromFormat("seconds=%d", GET_TD_SECONDS(self)));
}

if (GET_TD_MICROSECONDS(self) != 0) {
if (strlen(days) == 0 && strlen(seconds) == 0) {
sprintf(microseconds, "microseconds=%d", GET_TD_MICROSECONDS(self));
} else {
sprintf(microseconds, ", microseconds=%d", GET_TD_MICROSECONDS(self));
}
PyList_Append(args, PyUnicode_FromFormat("microseconds=%d", GET_TD_MICROSECONDS(self)));
}

return PyUnicode_FromFormat("%s(%s%s%s)",
PyObject *args_string = PyUnicode_Join(PyUnicode_FromString(", "), args);

return PyUnicode_FromFormat("%s(%S)",
Py_TYPE(self)->tp_name,
days,
seconds,
microseconds);
args_string);
}

static PyObject *
Expand Down