[MERGE] bzrlib.osutils fixes

John Arbash Meinel john at arbash-meinel.com
Fri Mar 9 15:54:37 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert Collins wrote:
> Robert Collins has voted -1.
> Status is now: Vetoed
> Comment:
> _directory_kind is not being used yet, but its definately not a
> misfeature IMNSHO:
> 
> :!python -m timeit -s 'f = "foo"; b = "bar"' 'f == b'
> 1000000 loops, best of 3: 0.26 usec per loop
> 
> :!python -m timeit -s 'f = "foo"; b = "bar"' 'f != b'
> 1000000 loops, best of 3: 0.265 usec per loop
> 
> :!python -m timeit -s 'f = "foo"; b = "bar"' 'f is b'
> 1000000 loops, best of 3: 0.213 usec per loop
> 
> :!python -m timeit -s 'f = "foo"; b = "bar"' 'f is not b'
> 1000000 loops, best of 3: 0.211 usec per loop
> 
> 
> For details, see:
> http://bundlebuggy.aaronbentley.com/request/%3C45F122CD.4090800%40hlabs.spb.ru%3E

There are a few things that you should consider, however.

1) 'directory' is 'directory'. String constants are automatically
interned if the "look like python variables" (according to spiv).

2) We currently read off disk, because we want to avoid the extra
function call in an inner loop. I'm actually thinking we could change it
to intern() and probably not lose a whole lot.

3) Do we really think it will ever be safe to change all of our "if
x.kind == 'directory'" to "if x.kind is 'directory':" or even "if x.kind
is _directory_kind".

4) If you have _directory_kind, it will be a variable lookup. (possibly
in locals, frequently in globals). I don't know exactly how python
handles constants, but "if x is 'directory'" could certainly be faster
than "if x is _directory_kind".

5) 'if x == _directory_kind' is a bit less transparent than "if x ==
'directory'". So there is a readability factor.

6) If we do decide to go with _foo_kind, then we should be consistent,
and have _file_kind, _directory_kind, _symlink_kind, etc.

I'll merge Dmitry's original patch, because I think the fix is good. But
I really think his later patch is better.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF8YM9JdeBCYSNAAMRArPhAKDOejwZtUH5krH0qE7Qda/Zrw1dPACgxQg/
kBpG2wwtugyaYEy3wKT2rhU=
=48sD
-----END PGP SIGNATURE-----



More information about the bazaar mailing list