]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-138535: Optimize fill_time for typical timestamps (#138537)
authorJeffrey Bosboom <jbosboom@jeffreybosboom.com>
Tue, 9 Sep 2025 09:05:54 +0000 (02:05 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Sep 2025 09:05:54 +0000 (11:05 +0200)
commitd4825ac27cba68d02221e13910ea42ee9caac38c
tree7c7d7f112017cd4e5bed9c97644ee56788c94dca
parent5edfe55acf29f7c36f585bcff7f96c244c43f9ae
gh-138535: Optimize fill_time for typical timestamps (#138537)

While file timestamps can be anything the file system can store, most
lie between the recent past and the near future.  Optimize fill_time()
for typical timestamps in three ways:

- When possible, convert to nanoseconds with C arithmetic.
- When using C arithmetic and the seconds member is not required (for
  st_birthtime), avoid creating a long object.
- When using C arithmetic, reorder the code to avoid the null checks
  implied in Py_XDECREF().

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_os.py
Misc/NEWS.d/next/Library/2025-09-06-20-09-32.gh-issue-138535.mlntEe.rst [new file with mode: 0644]
Modules/posixmodule.c