Re: small code smell
Tim Hemel <[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Sep 01, 2003 at 12:04:46PM +0200, Bram Moolenaar wrote: > > Tim Hemel wrote: > > > Here's one that can perhaps be made a lot simpler, by borrowing someone else's > > code: > > > > shorten_name in Util.py > > > > A similar function is described in the Python Cookbook: > > > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/208993 > > > > periperi(116):~/programs> python relpath.py > > from /a/b/c/d to /a/b/c1/d1 -> ../../c1/d1 > > from /foo/bdir/foo.o to /foo/test -> ../../test > > from /foo/test to /foo/bdir/foo.o -> ../bdir/foo.o > > > > The functions do not work with . and .. in the filenames, but that can be > > solved by always normalizing the pathnames. > > This doesn't look simpler at all. Looking at the code I can guess it's > a lot slower, because commonpath() calls itself recursively for every > character. This smells like a classroom example... It looked a lot easier to understand, as is usually the case with classroom examples. > Path handling needs to be fast, because it's done very often. And it > also needs to take care of forward- vs back-slashes. > > Reminds me to do some profiling one of these days... Tim -- Zen Microsystems: we're the om in .commmmmmmmm... ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf