]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-126565: Skip `zipfile.Path.exists` check in write mode (GH-126576) (#126642)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 10 Nov 2024 15:21:47 +0000 (16:21 +0100)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2024 15:21:47 +0000 (15:21 +0000)
commit0d3aa25ee41d03bb8b4e6d90beee15835321f724
tree8a8cec856c963076d530e0d76b2283800bc586ee
parentfa3ee75e6a1732e03d4c5a651bd7d6f39f60974c
[3.13] gh-126565: Skip `zipfile.Path.exists` check in write mode (GH-126576) (#126642)

gh-126565: Skip `zipfile.Path.exists` check in write mode (GH-126576)

When `zipfile.Path.open` is called, the implementation will check
whether the path already exists in the ZIP file. However, this check is
only required when the ZIP file is in read mode. By swapping arguments
of the `and` operator, the short-circuiting will prevent the check from
being run in write mode.

This change will improve the performance of `open()`, because checking
whether a file exists is slow in write mode, especially when the archive
has many members.
(cherry picked from commit 160758a574d12bf0d965d8206136e7da4f4fd6c3)

Co-authored-by: Jan Hicken <janhicken@users.noreply.github.com>
Lib/zipfile/_path/__init__.py
Misc/NEWS.d/next/Library/2024-11-08-11-06-14.gh-issue-126565.dFFO22.rst [new file with mode: 0644]