"Moejoe000" posted a comment on MediaWiki.r109847.
URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/109847#c29943

Commit summary for MediaWiki.r109847:

Fix for r109720: replace the last two regexes with plain string functions. The 
regular expression used for stripping the last path component from the output 
was inefficient, because PCRE does not optimise "$" anchors correctly. It scans 
the entire string forwards, instead of scanning backwards starting from the 
anchor. Passes tests.

Moejoe000's comment:

The whole wfRemoveDotSegments seems unreasonably complicated. 

The following function (own work, public domain) does the same (here the 
buffers of RFC3986 are implemented as arrays where all the comparisons are much 
easier to code) and speeds up by a factor of 4 and does (due to my tests) the 
same as the original version:

 function wfRemoveDotSegments( $urlPath ) {
        $parts = explode( '/', $urlPath );
        $out = array();
        foreach( $parts as $part ) {
                if( $part === '..' ) {
                        if( count( $out ) > 0 ) {
                                array_pop( $out );              
                                if( count( $out ) === 0 ) {
                                        $out[] = '­';
                                }
                        }
                        $slashAtEnd = true;
                } elseif(  $part === '.' ) {
                        $slashAtEnd = true;
                } else {
                        $out[] = $part;
                        $slashAtEnd = false;
                }
        }
        if( $slashAtEnd ) $out[] = '­';
        return implode( '/', $out );
 }

_______________________________________________
MediaWiki-CodeReview mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview

Reply via email to