forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-99726: Add 'fast' argument to os.[l]stat for faster calculation
When passed as True, only st_mode's type bits, st_size and st_mtime[_nsec] are guaranteed to be set. Other fields may also be set for a given Python version on a given platform version, but may change without warning (in the case of OS changes - Python will try to keep them stable). This first implementation uses a new Windows API that is significantly faster, provided the volume identifier is not required. Other optimizations may be added later.
- Loading branch information
Showing
11 changed files
with
375 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#ifndef Py_INTERNAL_FILEUTILS_WINDOWS_H | ||
#define Py_INTERNAL_FILEUTILS_WINDOWS_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "Py_BUILD_CORE must be defined to include this header" | ||
#endif | ||
|
||
#ifdef MS_WINDOWS | ||
|
||
#if !defined(NTDDI_WIN10_NI) || !(NTDDI_VERSION >= NTDDI_WIN10_NI) | ||
typedef struct _FILE_STAT_BASIC_INFORMATION { | ||
LARGE_INTEGER FileId; | ||
LARGE_INTEGER CreationTime; | ||
LARGE_INTEGER LastAccessTime; | ||
LARGE_INTEGER LastWriteTime; | ||
LARGE_INTEGER ChangeTime; | ||
LARGE_INTEGER AllocationSize; | ||
LARGE_INTEGER EndOfFile; | ||
ULONG FileAttributes; | ||
ULONG ReparseTag; | ||
ULONG NumberOfLinks; | ||
ULONG DeviceType; | ||
ULONG DeviceCharacteristics; | ||
} FILE_STAT_BASIC_INFORMATION; | ||
|
||
typedef enum _FILE_INFO_BY_NAME_CLASS { | ||
FileStatByNameInfo, | ||
FileStatLxByNameInfo, | ||
FileCaseSensitiveByNameInfo, | ||
FileStatBasicByNameInfo, | ||
MaximumFileInfoByNameClass | ||
} FILE_INFO_BY_NAME_CLASS; | ||
#endif | ||
|
||
typedef BOOL (WINAPI *PGetFileInformationByName)( | ||
PCWSTR FileName, | ||
FILE_INFO_BY_NAME_CLASS FileInformationClass, | ||
PVOID FileInfoBuffer, | ||
ULONG FileInfoBufferSize | ||
); | ||
|
||
static inline BOOL GetFileInformationByName( | ||
PCWSTR FileName, | ||
FILE_INFO_BY_NAME_CLASS FileInformationClass, | ||
PVOID FileInfoBuffer, | ||
ULONG FileInfoBufferSize | ||
) { | ||
static PGetFileInformationByName GetFileInformationByName = NULL; | ||
static int GetFileInformationByName_init = -1; | ||
|
||
if (GetFileInformationByName_init < 0) { | ||
HMODULE hMod = LoadLibraryW(L"api-ms-win-core-file-l2-1-4"); | ||
GetFileInformationByName_init = 0; | ||
if (hMod) { | ||
GetFileInformationByName = (PGetFileInformationByName)GetProcAddress( | ||
hMod, "GetFileInformationByName"); | ||
if (GetFileInformationByName) { | ||
GetFileInformationByName_init = 1; | ||
} else { | ||
FreeLibrary(hMod); | ||
} | ||
} | ||
} | ||
|
||
if (GetFileInformationByName_init <= 0) { | ||
SetLastError(ERROR_NOT_SUPPORTED); | ||
return FALSE; | ||
} | ||
return GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize); | ||
} | ||
|
||
#endif | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2022-11-23-15-15-59.gh-issue-99726.6m-YhG.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Adds `fast` argument to :func:`os.stat` and :func:`os.lstat` to enable | ||
performance optimizations by skipping some fields in the result. |
Oops, something went wrong.