Ticket #35667: 35667.2.diff
| File 35667.2.diff, 2.8 KB (added by , 8 years ago) |
|---|
-
src/wp-includes/class-wp-text-diff-renderer-table.php
56 56 protected $compat_fields = array( '_show_split_view', 'inline_diff_renderer', '_diff_threshold' ); 57 57 58 58 /** 59 * Caches the output of count_chars() in compute_string_distance() 60 * 61 * @var array 62 * @since 5.0.0 63 */ 64 protected $count_cache = array(); 65 66 /** 67 * Caches the difference calculation in compute_string_distance() 68 * 69 * @var array 70 * @since 5.0.0 71 */ 72 protected $difference_cache = array(); 73 74 /** 59 75 * Constructor - Call parent constructor with params array. 60 76 * 61 77 * This will set class properties based on the key value pairs in the array. … … 396 412 if ( false === $final_pos ) { // This orig is paired with a blank final. 397 413 array_splice( $final_rows, $orig_pos, 0, -1 ); 398 414 } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. 399 $diff_pos = $final_pos - $orig_pos; 400 while ( $diff_pos < 0 ) { 401 array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); 402 } 415 $diff_array = range( -1, $final_pos - $orig_pos ); 416 array_splice( $final_rows, $orig_pos, 0, $diff_array ); 403 417 } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. 404 $diff_pos = $orig_pos - $final_pos; 405 while ( $diff_pos < 0 ) { 406 array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); 407 } 418 $diff_array = range( -1, $orig_pos - $final_pos ); 419 array_splice( $orig_rows, $orig_pos, 0, $diff_array ); 408 420 } 409 421 } 410 422 … … 435 447 */ 436 448 public function compute_string_distance( $string1, $string2 ) { 437 449 // Vectors containing character frequency for all chars in each string 438 $chars1 = count_chars( $string1 ); 439 $chars2 = count_chars( $string2 ); 450 if ( ! isset( $this->count_cache[ $string1 ] ) ) { 451 $this->count_cache[ $string1 ] = count_chars($string1); 452 } 453 if ( ! isset( $this->count_cache[ $string2 ] ) ) { 454 $this->count_cache[ $string2 ] = count_chars($string2); 455 } 456 457 $chars1 = $this->count_cache[ $string1 ]; 458 $chars2 = $this->count_cache[ $string2 ]; 459 460 $difference_key = implode( ',', $chars1 ) . ':' . implode( ',', $chars2 ); 461 if ( ! isset( $this->difference_cache[ $difference_key ] ) ) { 462 // L1-norm of difference vector. 463 $this->difference_cache[ $difference_key ] = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) ); 464 } 465 466 $difference = $this->difference_cache[ $difference_key ]; 440 467 441 468 // L1-norm of difference vector. 442 469 $difference = array_sum( array_map( array( $this, 'difference' ), $chars1, $chars2 ) );