8000 gh-91146: More reduce allocation size of list from str.split/rsplit by corona10 · Pull Request #95493 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-91146: More reduce allocation size of list from str.split/rsplit #95493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 1, 2022
Merged
Changes from 1 commit
Commits
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
Add comment for len2 == 0
  • Loading branch information
corona10 committed Jul 31, 2022
commit 2ebc918d03af0c60f95f4ca02a866ed13e895e33
6 changes: 4 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9733,7 +9733,8 @@ split(PyObject *self,
kind2 = PyUnicode_KIND(substring);
len2 = PyUnicode_GET_LENGTH(substring);
if (maxcount < 0) {
maxcount = len2 == 0 ? (len1 + 1) / 2 : (len1 / len2) + 1;
// if len2 == 0, it will raise TypeError.
maxcount = len2 == 0 ? 0 : (len1 / len2) + 1;
}
if (kind1 < kind2 || len1 < len2) {
out = PyList_New(1);
Expand Down Expand Up @@ -9823,7 +9824,8 @@ rsplit(PyObject *self,
kind2 = PyUnicode_KIND(substring);
len2 = PyUnicode_GET_LENGTH(substring);
if (maxcount < 0) {
maxcount = len2 == 0 ? (len1 + 1) / 2 : (len1 / len2) + 1;
// if len2 == 0, it will raise TypeError.
maxcount = len2 == 0 ? 0 : (len1 / len2) + 1;
}
if (kind1 < kind2 || len1 < len2) {
out = PyList_New(1);
Expand Down
0