FAQ
No, the order is (or could be) important - it's going to depend on what
you're doing. That's part of the reason my current solution doesn't work -
it's using separate lists for once-listeners and many-listeners, which
means I don't know what order they were added... that'll have to change too.

Thanks though :-)


On Wed, Mar 19, 2014 at 10:22 PM, Dan Kortschak wrote:
On Wed, 2014-03-19 at 22:13 -0500, Rasmus Schultz wrote:
Given that "deleting" a slice would require you to copy and
reconstruct the entire thing every time, I'm thinking you might as
well initialize a new slice *before *you start the iteration -
assuming most items are going to stay (which they are) you can then
simply allocate a size equal to the current number of listeners, then
copy every recurring listener to the new slice as you go.

This should be a lot more efficient than a full copy for every delete?
If you are not concerned with the order of the elements in the slice,
you can do an efficient delete operation based on end swapping:

func (l ListenerList) delete(i int) ListenerList {
l[i], l[len(l)-1] = l[len(l)-1], Listener{} // Help the GC here.
return l[:len(l)-1]
}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 30 of 30 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 17, '14 at 3:34a
activeMar 20, '14 at 3:25a
posts30
users14
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase