[Python-checkins] python/dist/src/Lib macpath.py,1.40,1.41 ntpath.py,1.51,1.52 posixpath.py,1.54,1.55

loewis@users.sourceforge.net loewis@users.sourceforge.net
Thu, 12 Dec 2002 12:30:22 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv24335/Lib

Modified Files:
	macpath.py ntpath.py posixpath.py 
Log Message:
Patch #536661: Improve performance of splitext. Add test_macpath.


Index: macpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/macpath.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** macpath.py	8 Oct 2002 02:44:30 -0000	1.40
--- macpath.py	12 Dec 2002 20:30:19 -0000	1.41
***************
*** 63,80 ****
      It is always true that root + ext == p."""
  
!     root, ext = '', ''
!     for c in p:
!         if c == ':':
!             root, ext = root + ext + c, ''
!         elif c == '.':
!             if ext:
!                 root, ext = root + ext, c
!             else:
!                 ext = c
!         elif ext:
!             ext = ext + c
!         else:
!             root = root + c
!     return root, ext
  
  
--- 63,71 ----
      It is always true that root + ext == p."""
  
!     i = p.rfind('.')
!     if i<=p.rfind(':'):
!         return p, ''
!     else:
!         return p[:i], p[i:]
  
  

Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -d -r1.51 -r1.52
*** ntpath.py	9 Oct 2002 07:56:04 -0000	1.51
--- ntpath.py	12 Dec 2002 20:30:19 -0000	1.52
***************
*** 170,187 ****
      Extension is everything from the last dot to the end.
      Return (root, ext), either part may be empty."""
!     root, ext = '', ''
!     for c in p:
!         if c in ['/','\\']:
!             root, ext = root + ext + c, ''
!         elif c == '.':
!             if ext:
!                 root, ext = root + ext, c
!             else:
!                 ext = c
!         elif ext:
!             ext = ext + c
!         else:
!             root = root + c
!     return root, ext
  
  
--- 170,179 ----
      Extension is everything from the last dot to the end.
      Return (root, ext), either part may be empty."""
! 
!     i = p.rfind('.')
!     if i<=max(p.rfind('/'), p.rfind('\\')):
!         return p, ''
!     else:
!         return p[:i], p[i:]
  
  

Index: posixpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/posixpath.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** posixpath.py	9 Nov 2002 05:08:06 -0000	1.54
--- posixpath.py	12 Dec 2002 20:30:20 -0000	1.55
***************
*** 79,96 ****
      """Split the extension from a pathname.  Extension is everything from the
      last dot to the end.  Returns "(root, ext)", either part may be empty."""
!     root, ext = '', ''
!     for c in p:
!         if c == '/':
!             root, ext = root + ext + c, ''
!         elif c == '.':
!             if ext:
!                 root, ext = root + ext, c
!             else:
!                 ext = c
!         elif ext:
!             ext = ext + c
!         else:
!             root = root + c
!     return root, ext
  
  
--- 79,87 ----
      """Split the extension from a pathname.  Extension is everything from the
      last dot to the end.  Returns "(root, ext)", either part may be empty."""
!     i = p.rfind('.')
!     if i<=p.rfind('/'):
!         return p, ''
!     else:
!         return p[:i], p[i:]