Commit 3128104f authored by Benjamin Peterson's avatar Benjamin Peterson

fix merge_collapse to actually maintain the invariant it purports to (closes #23515)

See
de Gouw, Stijn and Rot, Jurriaan and de Boer, Frank S and Bubel, Richard and Hähnle, Reiner
"OpenJDK’s java.utils.Collection.sort() is broken: The good, the bad and the worst case"
parent 445c4b19
...@@ -1800,7 +1800,8 @@ merge_collapse(MergeState *ms) ...@@ -1800,7 +1800,8 @@ merge_collapse(MergeState *ms)
assert(ms); assert(ms);
while (ms->n > 1) { while (ms->n > 1) {
Py_ssize_t n = ms->n - 2; Py_ssize_t n = ms->n - 2;
if (n > 0 && p[n-1].len <= p[n].len + p[n+1].len) { if ((n > 0 && p[n-1].len <= p[n].len + p[n+1].len) ||
(n > 1 && p[n-2].len <= p[n-1].len + p[n].len)) {
if (p[n-1].len < p[n+1].len) if (p[n-1].len < p[n+1].len)
--n; --n;
if (merge_at(ms, n) < 0) if (merge_at(ms, n) < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment