<div dir="ltr"><div><div><div>For example, another strategy for removing would be to move elements on the shortest side, that is increment firstIndex if removedIndex &lt; (firstIndex + lastIndex // 2).<br></div>This is currently not the case because the replaceFrom:to:with:startingAt: did use a fragile memcopy instead of memmove, but I swear I saw such implementation once in my life...<br>
</div>But if someone changes that someday, the reverseDo: strategy will break.<br><br></div>Nicolas<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/4 Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, 3 Jul 2013, Chris Muller wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a case where I need to remove certain entries from an<br>
OrderedCollection that will be called very frequently.  I therefore<br>
want to avoid copying the collection (to safely remove while<br>
enumerating) but it seems #reverseDo: can do what I want.<br>
<br>
 myCollection reverseDo: [ : each | each meetsSomeCriteria ifTrue: [<br>
myCollection remove: each ] ]<br>
<br>
Does anyone see any problem with doing this?<br>
</blockquote>
<br></div></div>
Yes. Once the implementation of #remove:ifAbsent: changes, your code might break. You should use #removeAllSuchThat: as Bert suggested, which was designed to do exactly what you want. It has guaranteed O(n) runtime, unlike your #reverseDo: &quot;hack&quot;, which has O(n*n).<br>

<br>
If your OrderedCollection is large, then you should probably use another data structure.<br>
<br>
<br>
Levente<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
</blockquote>
<br>
</blockquote></div><br></div>