Rev 5244: Change the object-level functions into module-level functions. in http://bazaar.launchpad.net/~jameinel/bzr/readdir_cleanup
John Arbash Meinel
john at arbash-meinel.com
Thu May 20 23:06:49 BST 2010
At http://bazaar.launchpad.net/~jameinel/bzr/readdir_cleanup
------------------------------------------------------------
revno: 5244
revision-id: john at arbash-meinel.com-20100520220639-bvpvs36169honnfe
parent: pqm at pqm.ubuntu.com-20100520092748-oa7knubtqio8l2rc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: readdir_cleanup
timestamp: Thu 2010-05-20 17:06:39 -0500
message:
Change the object-level functions into module-level functions.
We didn't ever change them per-instance, just had them there for fast lookups.
But lookups are even faster at the module level, because they are never exposed
and you don't have to worry about inheritance.
-------------- next part --------------
=== modified file 'bzrlib/_readdir_pyx.pyx'
--- a/bzrlib/_readdir_pyx.pyx 2010-02-17 17:11:16 +0000
+++ b/bzrlib/_readdir_pyx.pyx 2010-05-20 22:06:39 +0000
@@ -106,15 +106,22 @@
int closedir(DIR * dir)
dirent *readdir(DIR *dir)
+cdef object _directory
_directory = 'directory'
+cdef object _chardev
_chardev = 'chardev'
+cdef object _block
_block = 'block'
+cdef object _file
_file = 'file'
+cdef object _fifo
_fifo = 'fifo'
+cdef object _symlink
_symlink = 'symlink'
+cdef object _socket
_socket = 'socket'
+cdef object _unknown
_unknown = 'unknown'
-_missing = 'missing'
# add a typedef struct dirent dirent to workaround pyrex
cdef extern from 'readdir.h':
@@ -161,25 +168,12 @@
from bzrlib import osutils
+cdef object _safe_utf8
+_safe_utf8 = osutils.safe_utf8
cdef class UTF8DirReader:
"""A dir reader for utf8 file systems."""
- cdef readonly object _safe_utf8
- cdef _directory, _chardev, _block, _file, _fifo, _symlink
- cdef _socket, _unknown
-
- def __init__(self):
- self._safe_utf8 = osutils.safe_utf8
- self._directory = _directory
- self._chardev = _chardev
- self._block = _block
- self._file = _file
- self._fifo = _fifo
- self._symlink = _symlink
- self._socket = _socket
- self._unknown = _unknown
-
def kind_from_mode(self, int mode):
"""Get the kind of a path from a mode status."""
return self._kind_from_mode(mode)
@@ -187,25 +181,24 @@
cdef _kind_from_mode(self, int mode):
# Files and directories are the most common - check them first.
if S_ISREG(mode):
- return self._file
+ return _file
if S_ISDIR(mode):
- return self._directory
+ return _directory
if S_ISCHR(mode):
- return self._chardev
+ return _chardev
if S_ISBLK(mode):
- return self._block
+ return _block
if S_ISLNK(mode):
- return self._symlink
+ return _symlink
if S_ISFIFO(mode):
- return self._fifo
+ return _fifo
if S_ISSOCK(mode):
- return self._socket
- return self._unknown
+ return _socket
+ return _unknown
def top_prefix_to_starting_dir(self, top, prefix=""):
"""See DirReader.top_prefix_to_starting_dir."""
- return (self._safe_utf8(prefix), None, None, None,
- self._safe_utf8(top))
+ return (_safe_utf8(prefix), None, None, None, _safe_utf8(top))
def read_dir(self, prefix, top):
"""Read a single directory from a utf8 file system.
More information about the bazaar-commits
mailing list