if(index < arr.length - 1) arr[index] = arr.pop();else arr.pop();
var testLen = 10000;var arrSplice:Array<String> = new Array<String>();var arrPop:Array<String> = new Array<String>();for (i in 0 ... 10000){ arrSplice.push(cast(i)); arrPop.push(cast(i));}
var timer = Lib.getTimer();
testLen = arrSplice.length;while (testLen > 0){ arrSplice.splice(--testLen, 1);}trace("Splice test time: " + cast(Lib.getTimer() - timer) + "ms");timer = Lib.getTimer();
testLen = arrPop.length;while (arrPop.length > 0){ if(arrPop.length > 1) arrPop[0] = arrPop.pop(); else arrPop.pop();}trace("Pop test time: " + cast(Lib.getTimer() - timer) + "ms");
This is called "swap and pop" if you want to find other versions of it. It's a good trick.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en