Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array appends are quadratic
- X-seq: zsh-workers 37240
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: Array appends are quadratic
- Date: Fri, 27 Nov 2015 02:59:58 -0800
- 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=r7ssOEprUxID1H4/iJK+P+2Rg665qElc8C0HY7Fj0pk=; b=NlSmmAdPh2mZreJMqEoYq2kcb/BEhfLfq+nivYDqZwNrAB1KRQJAaMvtT0qafgXtgm 39D8NI2s1Yvm333GFs3/LG/21RbUynPlPHstLrCJ5hjWa4saSiYoWh4k+sVcBwUWdqHf 929xyuG3BZSdUBQwGYmT1ZyoTYP1ZAc4/MFYHk7uwid4e6S5oRWMlYkCGQW7cEh/8GQm zXME+yhv/22RlAQNuyE3j15KYNu9EN8cXl00uSv+8ltn8mEZABj9Zwh+HNTs3rFLI2Sv rjPp38VHG6WA4lNpRDmV4QfeO3EYXE7Gvw/0Rhhe3CtnIru2dOHw7C9tyyW8ad8XyQac vcSA==
- In-reply-to: <CAHYJk3S6_opij6An1DWt+8UDvDerooSyjkXfUfYJgBjUfNMC0Q@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20151127073730.GI1899@tarsus.local2> <CAHYJk3S6_opij6An1DWt+8UDvDerooSyjkXfUfYJgBjUfNMC0Q@mail.gmail.com>
On Nov 27, 9:26am, Mikael Magnusson wrote:
} Subject: Re: Array appends are quadratic
}
} According to your debug prints, the array is reallocated every time it
} is assigned to, even when the required element is already allocated.
} Doubling the allocation size would do nothing to fix that, presumably.
Right, this is generic code to handle array splicing, so starting from
an array with 200 elements,
a[100]=foo
and
a[50,150]=(foo)
use the same loop even though the former does not change the size of
the resulting array and the latter will waste 100 slots at the top.
I vaguely recall a conversation in which we decided that fewer code
branches was better than attempting to efficiently re-use array slots.
} % a[100]=foo
} params.c:2585: setarrvalue: Reallocating 'a' to size 100
} % a[5]=bar
} params.c:2585: setarrvalue: Reallocating 'a' to size 101
} % a[10]=bar
} params.c:2585: setarrvalue: Reallocating 'a' to size 101
}
} Do we have an... off-by-two bug somewhere?
No, it just always allocates 1 more than the largest occupied array
index position if the array isn't empty to begin with.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author