Re: small code smell

Bram Moolenaar <[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
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...

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...

-- 
       He was not in the least bit scared to be mashed into a pulp
       Or to have his eyes gouged out and his elbows broken;
       To have his kneecaps split and his body burned away
       And his limbs all hacked and mangled, brave Sir Robin.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.