nl_tokens: / * Does the same work as splice but with a slightly more convenient signature . The splice method has bugs in IE8 so this is the implementation we use on that platform .
pl_tokens: function replaceSim ( array , index , removeCount , insert ) { var add = insert ? insert . length : 0 , length = array . length , pos = fixArrayIndex ( array , index ) , remove , tailOldPos , tailNewPos , tailCount , lengthAfterRemove , i ; // we try to use Array.push when we can for efficiency... if ( pos === length ) { if ( add ) { array . push . apply ( array , insert ) ; } } else { remove = Math . min ( removeCount , length - pos ) ; tailOldPos = pos + remove ; tailNewPos = tailOldPos + add - remove ; tailCount = length - tailOldPos ; lengthAfterRemove = length - remove ; if ( tailNewPos < tailOldPos ) { // case A for ( i = 0 ; i < tailCount ; ++ i ) { array [ tailNewPos + i ] = array [ tailOldPos + i ] ; } } else if ( tailNewPos > tailOldPos ) { // case B for ( i = tailCount ; i -- ; ) { array [ tailNewPos + i ] = array [ tailOldPos + i ] ; } } // else, add == remove (nothing to do) if ( add && <mask> === lengthAfterRemove ) { array . length = lengthAfterRemove ; // truncate array array . push . apply ( array , insert ) ; } else { array . length = lengthAfterRemove + add ; // reserves space for ( i = 0 ; i < add ; ++ i ) { array [ pos + i ] = insert [ i ] ; } } } return array ; }