mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1109409 - improve mozpack.BaseFile.copy() performance on Windows; r=gps
mopack.BaseFile.copy() performs a generic read/write file copy. Windows has an explicit CopyFile() call that tests have shown to be significantly faster. Let's use that instead via the magic of ctypes.
This commit is contained in:
parent
5d706e16b5
commit
5a17186bee
@ -34,6 +34,24 @@ from tempfile import (
|
||||
NamedTemporaryFile,
|
||||
)
|
||||
|
||||
# For clean builds, copying files on win32 using CopyFile through ctypes is
|
||||
# ~2x as fast as using shutil.copyfile.
|
||||
if platform.system() != 'Windows':
|
||||
_copyfile = shutil.copyfile
|
||||
else:
|
||||
import ctypes
|
||||
_kernel32 = ctypes.windll.kernel32
|
||||
_CopyFileA = _kernel32.CopyFileA
|
||||
_CopyFileW = _kernel32.CopyFileW
|
||||
|
||||
def _copyfile(src, dest):
|
||||
# False indicates `dest` should be overwritten if it exists already.
|
||||
if isinstance(src, unicode) and isinstance(dest, unicode):
|
||||
_CopyFileW(src, dest, False)
|
||||
elif isinstance(src, str) and isinstance(dest, str):
|
||||
_CopyFileA(src, dest, False)
|
||||
else:
|
||||
raise TypeError('mismatched path types!')
|
||||
|
||||
class Dest(object):
|
||||
'''
|
||||
@ -135,7 +153,8 @@ class BaseFile(object):
|
||||
|
||||
if can_skip_content_check:
|
||||
if getattr(self, 'path', None) and getattr(dest, 'path', None):
|
||||
shutil.copy2(self.path, dest.path)
|
||||
_copyfile(self.path, dest.path)
|
||||
shutil.copystat(self.path, dest.path)
|
||||
else:
|
||||
# Ensure the file is always created
|
||||
if not dest.exists():
|
||||
|
Loading…
Reference in New Issue
Block a user