From 1f25c333a280561e86cc0af69af307b53ddbaaac Mon Sep 17 00:00:00 2001 From: felix Date: Mon, 7 Sep 2026 16:33:54 +0200 Subject: [PATCH 1/2] gh-156505: Speed up difflib.HtmlDiff for lopsided replacements (GH-156506) --- Lib/difflib.py | 8 ++++---- Lib/test/test_difflib.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index c081cd8606df5bb..54fc57db975b252 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -31,7 +31,7 @@ 'unified_diff', 'diff_bytes', 'HtmlDiff', 'Match'] from heapq import nlargest as _nlargest -from collections import namedtuple as _namedtuple +from collections import deque as _deque, namedtuple as _namedtuple from types import GenericAlias lazy from _colorize import can_colorize, get_theme @@ -1571,7 +1571,7 @@ def _line_pair_iterator(): is defined) does not need to be of module scope. """ line_iterator = _line_iterator() - fromlines,tolines=[],[] + fromlines, tolines = _deque(), _deque() while True: # Collecting lines of text until we have a from/to pair while (len(fromlines)==0 or len(tolines)==0): @@ -1584,8 +1584,8 @@ def _line_pair_iterator(): if to_line is not None: tolines.append((to_line,found_diff)) # Once we have a pair, remove them from the collection and yield it - from_line, fromDiff = fromlines.pop(0) - to_line, to_diff = tolines.pop(0) + from_line, fromDiff = fromlines.popleft() + to_line, to_diff = tolines.popleft() yield (from_line,to_line,fromDiff or to_diff) # Handle case where user does not want context differencing, just yield diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py index 5babe834e9beac2..8c554d7c95b5f6e 100644 --- a/Lib/test/test_difflib.py +++ b/Lib/test/test_difflib.py @@ -200,6 +200,26 @@ def test_mdiff_catch_stop_iteration(self): [((1, '\x00-2\x01'), (1, '\x00+3\x01'), True)], ) + def test_mdiff_lopsided_replace(self): + self.assertEqual( + list(difflib._mdiff(["a\n"] * 4, ["b\n"])), + [ + ((1, '\x00-a\n\x01'), (1, '\x00+b\n\x01'), True), + ((2, '\x00-a\n\x01'), ('', '\n'), True), + ((3, '\x00-a\n\x01'), ('', '\n'), True), + ((4, '\x00-a\n\x01'), ('', '\n'), True), + ], + ) + self.assertEqual( + list(difflib._mdiff(["a\n"], ["b\n"] * 4)), + [ + ((1, '\x00-a\n\x01'), (1, '\x00+b\n\x01'), True), + (('', '\n'), (2, '\x00+b\n\x01'), True), + (('', '\n'), (3, '\x00+b\n\x01'), True), + (('', '\n'), (4, '\x00+b\n\x01'), True), + ], + ) + patch914575_from1 = """ 1. Beautiful is beTTer than ugly. From 8b2433af48de8ecf9086529db0cfde8457d790f6 Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Mon, 7 Sep 2026 18:35:51 +0200 Subject: [PATCH 2/2] gh-152433: Allow building mimalloc for Windows UWP (GH-152477) --- Objects/mimalloc/prim/windows/prim.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Objects/mimalloc/prim/windows/prim.c b/Objects/mimalloc/prim/windows/prim.c index a038277ad21cb04..49652f65712abbc 100644 --- a/Objects/mimalloc/prim/windows/prim.c +++ b/Objects/mimalloc/prim/windows/prim.c @@ -12,6 +12,7 @@ terms of the MIT license. A copy of the license can be found in the file #include "mimalloc/atomic.h" #include "mimalloc/prim.h" #include // fputs, stderr +#include // NTSTATUS //--------------------------------------------- @@ -377,6 +378,7 @@ size_t _mi_prim_numa_node(void) { } size_t _mi_prim_numa_node_count(void) { +#ifdef MS_WINDOWS_DESKTOP ULONG numa_max = 0; GetNumaHighestNodeNumber(&numa_max); // find the highest node number that has actual processors assigned to it. Issue #282 @@ -399,6 +401,9 @@ size_t _mi_prim_numa_node_count(void) { numa_max--; } return ((size_t)numa_max + 1); +#else + return ((size_t)1); +#endif }