diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2006-11-28 16:34:28 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-11-28 16:34:28 +0000 |
commit | 149f92896345b1fd873a814721b6e042a8681593 (patch) | |
tree | b7b8dbe58bdd6aba31fcc12c7e92d55b6ae12749 | |
parent | ff2b4e4e8f319e9c7346d33a79a3e1458464b7e8 (diff) | |
download | forums-149f92896345b1fd873a814721b6e042a8681593.tar forums-149f92896345b1fd873a814721b6e042a8681593.tar.gz forums-149f92896345b1fd873a814721b6e042a8681593.tar.bz2 forums-149f92896345b1fd873a814721b6e042a8681593.tar.xz forums-149f92896345b1fd873a814721b6e042a8681593.zip |
begin working on getting this thing a bit faster. I need to finish the other calls, this commit actually will break the diff engine and the updater. The speed increase noticed is from 89 seconds to 22 seconds as well as saving a lot of memory.
git-svn-id: file:///svn/phpbb/trunk@6692 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/includes/diff/diff.php | 11 | ||||
-rw-r--r-- | phpBB/includes/diff/engine.php | 5 | ||||
-rw-r--r-- | phpBB/install/install_update.php | 53 |
3 files changed, 54 insertions, 15 deletions
diff --git a/phpBB/includes/diff/diff.php b/phpBB/includes/diff/diff.php index ca8d16fd3e..59124ae7ef 100644 --- a/phpBB/includes/diff/diff.php +++ b/phpBB/includes/diff/diff.php @@ -46,10 +46,17 @@ class diff * @param array $from_lines An array of strings. Typically these are lines from a file. * @param array $to_lines An array of strings. */ - function diff($from_lines, $to_lines) + function diff(&$from_content, &$to_content) { $diff_engine = &new diff_engine(); - $this->_edits = call_user_func_array(array($diff_engine, 'diff'), array($from_lines, $to_lines)); + + $match = array('#\r\n?#', "#([\n]+){2,}#u"); + $replace = array("\n", "\n"); + + $from_content = preg_replace($match, $replace, $from_content); + $to_content = preg_replace($match, $replace, $to_content); + + $this->_edits = call_user_func_array(array($diff_engine, 'diff'), array(explode("\n", $from_content), explode("\n", $to_content))); } /** diff --git a/phpBB/includes/diff/engine.php b/phpBB/includes/diff/engine.php index 5fcb317dd5..e7740a0584 100644 --- a/phpBB/includes/diff/engine.php +++ b/phpBB/includes/diff/engine.php @@ -49,8 +49,9 @@ class diff_engine { function diff($from_lines, $to_lines) { - array_walk($from_lines, array('diff', 'trim_newlines')); - array_walk($to_lines, array('diff', 'trim_newlines')); + // Remove empty lines... +// array_walk($from_lines, array('diff', 'trim_newlines')); +// array_walk($to_lines, array('diff', 'trim_newlines')); $n_from = sizeof($from_lines); $n_to = sizeof($to_lines); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 8bd94f036e..4a829f68dc 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -862,11 +862,19 @@ class install_update extends module // Check for this circumstance, the new file need to be up-to-date with the current file then... if (!file_exists($this->old_location . $original_file) && file_exists($this->new_location . $original_file) && file_exists($phpbb_root_path . $file)) { + $tmp = array( + 'file1' => file_get_contents($this->new_location . $original_file), + 'file2' => file_get_contents($phpbb_root_path . $file), + ); + // We need to diff the contents here to make sure the file is really the one we expect - $diff = &new diff(file($this->new_location . $original_file), file($phpbb_root_path . $file)); + $diff = &new diff($tmp['file1'], $tmp['file2']); + $empty = $diff->is_empty(); + + unset($tmp, $diff); // if there are no differences we have an up-to-date file... - if ($diff->is_empty()) + if ($empty) { $update_list['up_to_date'][] = $update_ary; return; @@ -883,16 +891,34 @@ class install_update extends module trigger_error($user->lang['INCOMPLETE_UPDATE_FILES'], E_USER_ERROR); } - $diff = &new diff(file($this->old_location . $original_file), file($phpbb_root_path . $file)); + $tmp = array( + 'file1' => file_get_contents($this->old_location . $original_file), + 'file2' => file_get_contents($phpbb_root_path . $file), + ); + + // We need to diff the contents here to make sure the file is really the one we expect + $diff = &new diff($tmp['file1'], $tmp['file2']); + $empty_1 = $diff->is_empty(); + + unset($tmp, $diff); + + $tmp = array( + 'file1' => file_get_contents($this->new_location . $original_file), + 'file2' => file_get_contents($phpbb_root_path . $file), + ); + + // We need to diff the contents here to make sure the file is really the one we expect + $diff = &new diff($tmp['file1'], $tmp['file2']); + $empty_2 = $diff->is_empty(); + + unset($tmp, $diff); // If the file is not modified we are finished here... - if ($diff->is_empty()) + if ($empty_1) { // Further check if it is already up to date - it could happen that non-modified files // slip through - $diff = &new diff(file($this->new_location . $original_file), file($phpbb_root_path . $file)); - - if ($diff->is_empty()) + if ($empty_2) { $update_list['up_to_date'][] = $update_ary; return; @@ -903,10 +929,9 @@ class install_update extends module } // If the file had been modified then we need to check if it is already up to date - $diff = &new diff(file($this->new_location . $original_file), file($phpbb_root_path . $file)); // if there are no differences we have an up-to-date file... - if ($diff->is_empty()) + if ($empty_2) { $update_list['up_to_date'][] = $update_ary; return; @@ -922,10 +947,16 @@ class install_update extends module return; } + $tmp = array( + 'file1' => file_get_contents($phpbb_root_path . $file), + 'file2' => implode("\n", $diff->merged_output()), + ); + // now compare the merged output with the original file to see if the modified file is up to date - $diff = &new diff(file($phpbb_root_path . $file), $diff->merged_output()); + $diff = &new diff($tmp['file1'], $tmp['file2']); + $empty = $diff->is_empty(); - if ($diff->is_empty()) + if ($empty) { $update_list['up_to_date'][] = $update_ary; return; |