Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version:content-type;
        bh=cKGEk/w8FPuWZ2Qtp37TOgyk3mTA0gzIxui5lwpi9gk=;
        b=fWGgrlnUnKAKJ6f7Mq2tpRtt58N0AsHwsVdXXco0y5K7NAa0k12sfb8QJpwcKUbZRw
         /870Nyc5btanwgwltIks+qdh8FhMR3GzykjG45468g+eQ5ALYzVok/M1WCSnAkb26RkR
         eaQdtHJzzcWliCsgj3LR7HPEtWm+mf8mma5z2D1DM5oXcRJ5Zz+cdMeBDY6cQPOi+ugf
         y//Uyf4UkvYNMgY6A1hNJEwFJboaikUddLThwC4p70kLwbx84rGzUpuiM6bU/jnZakU0
         wbBBluR6V9mZpZ//gX024Q0Qk+tTYbA9mJSClCM2Noyh+2SjZRAu2j3kxXi58JWllDv/
         py2w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version:content-type;
        bh=cKGEk/w8FPuWZ2Qtp37TOgyk3mTA0gzIxui5lwpi9gk=;
        b=kkJCEirYA6cZuN3Di6Vnhj98bbHqOwZkzdIiYbe5Ip2OK7i7h/Q32xuW+t7wC/6L/s
         qjsxTmGnVPLGO1bVYfHWmHCXaEmWIINWAfzxDSqK71tkXH9PO17gS5sNUc0U1ZvwR13o
         pICFGUpCIO3qMXEBbyUzt4zRQwKv+gI3I8mCGcWv98Fn4o5bdthJhi4O9Sy0A8Furi5k
         DActyDxi70jCngml4jtPUWBvJ4GrwMLqlY4DX6zPmNcseEeUL83UHVFr8uKBB1XHOeGR
         ZsWHCm6bT3lDS2H73qB4WPK3d+77QrvGEg1b6vq+v6x6TY+YPAiEChoIBkkTnHAD0yja
         WOHg==
X-Gm-Message-State: AG10YOSr5Gc13aIDOpCiEfYHrR0x0upJ3nuvxkIDaKRxFdg31xzBCZO2CLHuaOIcgVBFjQ==
X-Received: by 10.66.147.136 with SMTP id tk8mr46641175pab.157.1453934997753;
        Wed, 27 Jan 2016 14:49:57 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160127145041.ZM6525@torch.brasslantern.com>
Date: Wed, 27 Jan 2016 14:50:41 -0800
In-Reply-To: <CAKc7PVB6x-Eip=v1ctT_Ehf762MXHgBdxP1d7AwcQKX=B5sg8w@mail.gmail.com>
Comments: In reply to Sebastian Gniazdowski <sgniazdowski@gmail.com>
        "fpath+="${(u)fpath[@]}" can hog system" (Jan 27, 10:36am)
References: <CAKc7PVB6x-Eip=v1ctT_Ehf762MXHgBdxP1d7AwcQKX=B5sg8w@mail.gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: fpath+="${(u)fpath[@]}" can hog system
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 37817

On Jan 27, 10:36am, Sebastian Gniazdowski wrote:
}
} repeat 20; do fpath+="${(u)fpath[@]}"; done

Why would you do that?  What's the intended result?

Appending a string to an array creates a single new array element; it
doesn't matter that you've used [@] inside the double quotes, you are
still appending a new single element to the array every time.  Since
the new element consists of all the previous elements joined, it is
always unique and (u) will never filter out anything.

And then all of that will be duplicated as a single colon-separated
string in $FPATH.

Yeah, if you increase the size (in bytes) of $fpath by 20! (factorial),
and then make a copy of that, you are going to consume a buttload of
resources.

If what you mean is to append new elements to the array, you want array
assignment syntax:

fpath+=("${(u)fpath[@]}")

But even that probably doesn't do what you meant. because unless you have
already done "typeset -U fpath" all the existing elements are still going
to be repeated twice ... and IF you HAVE done "typeset -U" then (u) is a
no-op.

