Mercurial > public > mercurial-scm > hg
diff mercurial/windows.py @ 8330:7de68012f86e
Windows: improve performance via buffered I/O
The posixfile_nt code hits the win32 file API directly, which
essentially amounts to performing a system call for every read and
write. This is slow.
We add a C extension that lets us use a Python file object instead,
but preserve our desired POSIX-like semantics (the ability to rename
or delete a file that is being accessed).
If the C extension is not available (e.g. in a VPS environment
without a compiler), we fall back to the posixfile_nt code.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Fri, 08 May 2009 15:52:26 -0700 |
parents | b87a50b7125c |
children | fa901423ac23 |
line wrap: on
line diff
--- a/mercurial/windows.py Thu Mar 26 13:14:35 2009 -0700 +++ b/mercurial/windows.py Fri May 08 15:52:26 2009 -0700 @@ -240,12 +240,23 @@ If gid is None, return the name of the current group.""" return None -posixfile = file try: # override functions with win32 versions if possible from win32 import * if not _is_win_9x(): posixfile = posixfile_nt + try: + # fast, buffered POSIX-like file support + from osutil import posixfile as _posixfile + def posixfile(name, mode='r', buffering=-1): + # wrap osutil.posixfile to provide friendlier exceptions + try: + return _posixfile(name, mode, buffering) + except WindowsError, err: + raise WinIOError(err) + posixfile.__doc__ = _posixfile.__doc__ + except ImportError: + # slow, unbuffered POSIX-like file support + posixfile = posixfile_nt except ImportError: - pass - + posixfile = file