[DGD] Resolve Path & Array Efficiency

Steve Foley zeppo1 at mindspring.com
Sat Feb 21 08:15:11 CET 2004


From: "Michael McKiel" <crashnbrn71 at yahoo.ca>

> I have come up with the follow way to resolve ".." in directory paths:
> /* Dirs has previously exploded path, and had "" & "." removed, as
>  * well as '~' /home/ recognition */

> Now I know efficiency hardly matters when dealing with such a small number of
> elements of an array, but what I was wondering - when dealing with MUCH
> larger array's would it be more/less efficient to be removing ({ nil })
> elements or to rebuild the array's via concatenation:
>     dirs = dirs[#1 .. #2] + dirs[#3 .. #4];

> Or is there really any difference at all?
> In this instance the code is much easier to read, and more recursive-like,
> than the resolve_path() that comes with Melville standard. Which perhaps can
> be a more relevant issue than efficiency sometimes I suppose :)

When I think of the normalize_path function, I think the major inefficiency that
could crop up is memory allocation (caused by new arrays).  Felix's
normalize_path basically minimizes the number of new arrays, and I honestly
couldn't write a more efficient algorithm (but that isn't saying a whole lot).
But you're right, it's not real easy to follow.  As for your algorithm, I'm not
really sure how DGD works but I'd have to assume a new array is allocated every
time it hits that dir -= ({ nil }) line (maybe two...the new dir and the ({
nil }) array).  So, that's potentially many more memory allocations for arrays.

But you're right.  In the final analysis, we're talking miniscule amounts of
resources.  It's likely more important that you can easily follow what the
function does than it is for the function to be maximally efficient.  Though,
I'd suggest the best of both worlds would be to look over the function and get
comfortable with how it works.  I mean, the technique he employs there might
come in handy in some future code where efficiency will be more critical.

--Steve

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list