https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112813
Revision: 112813 Author: nikerabbit Date: 2012-03-01 15:21:57 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Add upper limit for string length to compare, the time taken grows very fast. Mark the function static as it is used as such. Modified Paths: -------------- trunk/extensions/Translate/utils/TTMServer.php Modified: trunk/extensions/Translate/utils/TTMServer.php =================================================================== --- trunk/extensions/Translate/utils/TTMServer.php 2012-03-01 15:20:47 UTC (rev 112812) +++ trunk/extensions/Translate/utils/TTMServer.php 2012-03-01 15:21:57 UTC (rev 112813) @@ -201,7 +201,13 @@ $b = $row->tms_text; $lenB = mb_strlen( $b ); $len = min( $lenA, $lenB ); - $dist = self::levenshtein_php( $a, $b, $lenA, $lenB ); + if ( $len > 1000 ) { + // two strings of length 1500 ~ 10s + // two strings of length 2250 ~ 30s + $dist = $len; + } else { + $dist = self::levenshtein( $a, $b, $lenA, $lenB ); + } $quality = 1 - ( $dist / $len ); if ( $quality >= $this->config['cutoff'] ) { @@ -261,7 +267,7 @@ /** * The native levenshtein is limited to 255 bytes. */ - function levenshtein_php( $str1, $str2, $length1, $length2 ) { + public static function levenshtein( $str1, $str2, $length1, $length2 ) { if ( $length1 == 0 ) return $length2; if ( $length2 == 0 ) return $length1; if ( $str1 === $str2 ) return 0; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs