Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Re: Associative array ordering and selective unset (Re: Example function)



On Oct 14,  3:07pm, Bart Schaefer wrote:
} Subject: Re: PATCH: Re: Associative array ordering and selective unset (Re
}
} }  scanparamvals(HashNode hn, int flags)
} }  {
} } +	if (!(prog = patcompile(tmp, 0, NULL)) || !pattry(prog, scanstr))
} } +	    return;
} 
} It just seemed so unpleasant to recompile the pattern for every key ...

I should probably clarify what I mean by that.  In another post, I wrote:

    map=(
        '(*.(gz|Z))     zcat' 
        '(*.bz2)        bzip2 -dc'
        '(*.bz)         bzip -dc'
        '(*)            <'
        )
    eval 'for i do case $i in' ${(j( $i;; ))map} '$i;; esac done'

Note that with this trick, all the patterns get compiled once (when the
`case' is parsed) and then we can compare every $i to the "keys" without
recompiling any patterns.

Thus the above is going to be significantly more efficient than:

    typeset -A map
    map=(
        '(*.(gz|Z))'     'zcat' 
        '(*.bz2)'        'bzip2 -dc'
        '(*.bz)'         'bzip -dc'
        '(*)'            '<'
        )
    for i do eval $map[(k)$i] $i; done

But this is not to suggest we shouldn't keep Sven's patch.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author