protected function array_slice_cached(&$array, $offset, $length = null)
    {
        static $lastOffset = null;
        static $lastLength = null;
        static $cache      = null;

        // PHP has no support for by-reference comparing.
        // to prevent false positive hits, reset the cache when the oldWords or newWords is changed.
        if ($this->resetCache === true) {
            $cache = null;

            $this->resetCache = false;
        }

        if (
            $cache !== null &&
            $lastLength === $length &&
            $lastOffset === $offset
        ) { // Hit
            return $cache;
        } // Miss

        $lastOffset = $offset;
        $lastLength = $length;

        $cache = implode('', array_slice($array, $offset, $length));

        return $cache;
    }
protected function array_slice_cached(&$array, $offset, $length = null)
    {
        static $lastOffset = null;
        static $lastLength = null;
        static $cache      = null;

        // PHP has no support for by-reference comparing.
        // to prevent false positive hits, reset the cache when the oldWords or newWords is changed.
        if ($this->resetCache === true) {
            $cache = null;

            $this->resetCache = false;
        }

        if (
            $cache !== null &&
            $lastLength === $length &&
            $lastOffset === $offset
        ) { // Hit
            return $cache;
        } // Miss

        $lastOffset = $offset;
        $lastLength = $length;

        $cache = implode('', array_slice($array, $offset, $length));

        return $cache;
    }
protected function array_slice_cached ( & $ array , $ offset , $ length = null ) { static $ lastOffset = null ; static $ lastLength = null ; static $ cache = null ; // PHP has no support for by-reference comparing. // to prevent false positive hits, reset the cache when the oldWords or newWords is changed. if ( $ this -> resetCache === true ) { $ cache = null ; $ this -> resetCache = false ; } if ( $ cache !== null && $ lastLength === $ length && $ lastOffset === $ offset ) { // Hit return $ cache ; } // Miss $ lastOffset = $ offset ; $ lastLength = $ length ; $ cache = implode ( '' , array_slice ( $ array , $ offset , $ length ) ) ; return $ cache ; }
Special array_slice function that caches its last request.

The diff algorithm seems to request the same information many times in a row.
by returning the previous answer the algorithm preforms way faster.

The result is a string instead of an array, this way we safe on the amount of
memory intensive implode() calls.

@param array         &$array
@param integer       $offset
@param integer|null  $length

@return string
Special array_slice function that caches its last request .