Changeset 611

Show
Ignore:
Timestamp:
04/24/07 14:47:13 (2 years ago)
Author:
mikey
Message:

the need for speed: reduced amount of calls to file_exists

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/star/StarStreamWrapper.php

    r304 r611  
    4444     */ 
    4545    protected $id; 
    46      
     46 
    4747    /** 
    4848     * registers the class as stream wrapper for the star protocol 
     
    6262        self::$registered = true; 
    6363    } 
    64      
     64 
    6565    /** 
    6666     * returns index of requested archive 
     
    7272    { 
    7373        static $archives = array(); 
     74        if (isset($archives[$archive]) == true) { 
     75            return $archives[$archive]; 
     76        } 
     77         
     78        $archives[$archive] = array(); 
    7479        if (file_exists($archive) == false) { 
    7580            return array(); 
    7681        } 
    77          
    78         if (isset($archives[$archive]) == false) { 
    79             $archives[$archive] = array(); 
    80             $current            =& $archives[$archive]; 
    81          
    82             $current['handle']  = fopen($archive, 'rb'); 
    83             if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
    84                 fseek($current['handle'], __COMPILER_HALT_OFFSET__); 
    85             } else { 
    86                 fseek($current['handle'], 0); 
    87             } 
    8882             
    89             $header = unpack('a4id/c1version/a8indexsize/a14buildtime/a*reserved', fread($current['handle'], 0x0100)); 
    90             if (false === $header) { 
    91                 // invalid star file 
    92                 return array(); 
    93             } 
     83        $current            =& $archives[$archive]; 
     84        $current['handle']  = fopen($archive, 'rb'); 
     85        if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
     86            fseek($current['handle'], __COMPILER_HALT_OFFSET__); 
     87        } else { 
     88            fseek($current['handle'], 0); 
     89        } 
     90         
     91        $header = unpack('a4id/c1version/a8indexsize/a14buildtime/a*reserved', fread($current['handle'], 0x0100)); 
     92        if (false === $header) { 
     93            // invalid star file 
     94            return array(); 
     95        } 
     96         
     97        $current['index']  = array(); 
     98        $current['header'] = $header; 
     99        if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
     100            $current['header']['totalSize'] = __COMPILER_HALT_OFFSET__ + 0x0100; 
     101        } else { 
     102            $current['header']['totalSize'] = 0x0100; 
     103        } 
     104         
     105        for ($i = 0; $i < $header['indexsize']; $i++) { 
     106            $entry = unpack('a80id/a72filename/a80path/a8size/a8offset/a*reserved', 
     107                            fread($current['handle'], 0x0100) 
     108                     ); 
    94109             
    95             $current['index']  = array(); 
    96             $current['header'] = $header; 
    97             if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
    98                 $current['header']['totalSize'] = __COMPILER_HALT_OFFSET__ + 0x0100; 
    99             } else { 
    100                 $current['header']['totalSize'] = 0x0100; 
    101             } 
    102             for ($i = 0; $i < $header['indexsize']; $i++) { 
    103                 $entry = unpack('a80id/a72filename/a80path/a8size/a8offset/a*reserved', 
    104                                 fread($current['handle'], 0x0100) 
    105                 ); 
    106                  
    107                 $current['index'][$entry['id']]  = array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
    108                 $current['header']['totalSize'] += 0x0100 + ((int) $entry['size']); 
    109             } 
    110         } 
    111          
    112         return $archives[$archive]; 
    113     } 
    114      
     110            $current['index'][$entry['id']]  = array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
     111            $current['header']['totalSize'] += 0x0100 + ((int) $entry['size']); 
     112        } 
     113    } 
     114 
    115115    /** 
    116116     * returns the metadata of an archive 
     
    140140        return $metaData; 
    141141    } 
    142      
     142 
    143143    /** 
    144144     * open the stream 
     
    164164        return true; 
    165165    } 
    166      
     166 
    167167    /** 
    168168     * read the stream up to $count bytes 
     
    231231        return array('size' => $current['index'][$this->id]['size']); 
    232232    } 
    233      
     233 
    234234    /** 
    235235     * parses the path into class members