| | private function binarySearchIdx( |
| | string $indexFile, |
| | - $handle, |
| | + mixed $handle, |
| | int $start, |
| | int $end, |
| | string $binarySha, |
| | int $total |
| | ): int { |
| | - $key = "$indexFile:$start"; |
| | - $count = $end - $start; |
| | + $low = $start; |
| | + $high = $end - 1; |
| | $result = 0; |
| | - |
| | - if( !isset( $this->shaBucketCache[$key] ) ) { |
| | - fseek( $handle, 1032 + ($start * 20) ); |
| | - $this->shaBucketCache[$key] = fread( $handle, $count * 20 ); |
| | |
| | - fseek( $handle, 1032 + ($total * 24) + ($start * 4) ); |
| | - $this->offsetBucketCache[$key] = fread( $handle, $count * 4 ); |
| | - } |
| | + while( $result === 0 && $low <= $high ) { |
| | + $mid = ($low + $high) >> 1; |
| | |
| | - $shaBlock = $this->shaBucketCache[$key]; |
| | - $low = 0; |
| | - $high = $count - 1; |
| | - $found = -1; |
| | + fseek( $handle, 1032 + ($mid * 20) ); |
| | |
| | - while( $found === -1 && $low <= $high ) { |
| | - $mid = ($low + $high) >> 1; |
| | - $cmp = substr( $shaBlock, $mid * 20, 20 ); |
| | + $cmp = fread( $handle, 20 ); |
| | |
| | if( $cmp < $binarySha ) { |
| | $low = $mid + 1; |
| | } elseif( $cmp > $binarySha ) { |
| | $high = $mid - 1; |
| | } else { |
| | - $found = $mid; |
| | - } |
| | - } |
| | + fseek( $handle, 1032 + ($total * 24) + ($mid * 4) ); |
| | |
| | - if( $found !== -1 ) { |
| | - $packed = substr( $this->offsetBucketCache[$key], $found * 4, 4 ); |
| | - $offset = unpack( 'N', $packed )[1]; |
| | + $packed = fread( $handle, 4 ); |
| | + $offset = unpack( 'N', $packed )[1]; |
| | |
| | - if( $offset & 0x80000000 ) { |
| | - $pos64 = 1032 + ($total * 28) + (($offset & 0x7FFFFFFF) * 8); |
| | + if( $offset & 0x80000000 ) { |
| | + $pos = 1032 + ($total * 28) + (($offset & 0x7FFFFFFF) * 8); |
| | |
| | - fseek( $handle, $pos64 ); |
| | - $offset = unpack( 'J', fread( $handle, 8 ) )[1]; |
| | - } |
| | + fseek( $handle, $pos ); |
| | |
| | - $result = (int)$offset; |
| | + $offset = unpack( 'J', fread( $handle, 8 ) )[1]; |
| | + } |
| | + |
| | + $result = (int)$offset; |
| | + } |
| | } |
| | |