<div class="gmail_quote">On Thu, Jun 9, 2011 at 04:05, Victor Stinner <span dir="ltr"><<a href="mailto:victor.stinner@haypocalc.com">victor.stinner@haypocalc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Le jeudi 09 juin 2011 à 08:16 +0200, Georg Brandl a écrit :<br>
<div><div></div><div class="h5">> On 06/09/11 02:00, brian.curtin wrote:<br>
> > <a href="http://hg.python.org/cpython/rev/88e318166eaf" target="_blank">http://hg.python.org/cpython/rev/88e318166eaf</a><br>
> > changeset: 70713:88e318166eaf<br>
> > branch: 3.2<br>
> > parent: 70700:0aa3064d1cef<br>
> > user: Brian Curtin <<a href="mailto:brian@python.org">brian@python.org</a>><br>
> > date: Wed Jun 08 18:17:18 2011 -0500<br>
> > summary:<br>
> > Fix #11583. Changed os.path.isdir to use GetFileAttributes instead of os.stat.<br>
> ><br>
> > By changing to the Windows GetFileAttributes API in nt._isdir we can figure<br>
> > out if the path is a directory without opening the file via os.stat. This has<br>
> > the minor benefit of speeding up os.path.isdir by at least 2x for regular<br>
> > files and 10-15x improvements were seen on symbolic links (which opened the<br>
> > file multiple times during os.stat). Since os.path.isdir is used in<br>
> > several places on interpreter startup, we get a minor speedup in startup time.<br>
> ><br>
> > files:<br>
> > Lib/ntpath.py | 13 ++++++++++<br>
> > Misc/NEWS | 3 ++<br>
> > Modules/posixmodule.c | 37 +++++++++++++++++++++++++++++++<br>
> > 3 files changed, 53 insertions(+), 0 deletions(-)<br>
> ><br>
> ><br>
> > diff --git a/Lib/ntpath.py b/Lib/ntpath.py<br>
> > --- a/Lib/ntpath.py<br>
> > +++ b/Lib/ntpath.py<br>
> > @@ -672,3 +672,16 @@<br>
> > def sameopenfile(f1, f2):<br>
> > """Test whether two file objects reference the same file"""<br>
> > return _getfileinformation(f1) == _getfileinformation(f2)<br>
> > +<br>
> > +<br>
> > +try:<br>
> > + # The genericpath.isdir implementation uses os.stat and checks the mode<br>
> > + # attribute to tell whether or not the path is a directory.<br>
> > + # This is overkill on Windows - just pass the path to GetFileAttributes<br>
> > + # and check the attribute from there.<br>
> > + from nt import _isdir<br>
> > +except ImportError:<br>
> > + from genericpath import isdir as _isdir<br>
> > +<br>
> > +def isdir(path):<br>
> > + return _isdir(path)<br>
><br>
> Not that it matters, but ISTM that this would be faster as<br>
><br>
> try:<br>
> from nt import _isdir as isdir<br>
> except ImportError:<br>
> pass<br>
<br>
</div></div>I would matter if _isdir() had a docstring, but it doesn't :-)<br>
genericpath.isdir() has the following doc:<br>
<br>
def isdir(s):<br>
"""Return true if the pathname refers to an existing directory."""</blockquote><div><br></div><div><a href="http://hg.python.org/lookup/d40609dd01e0">http://hg.python.org/lookup/d40609dd01e0</a> adds the docstring back in and redoes the imports as Georg mentioned, which is better.<br>
Thanks for having a look. </div></div>