From bd8fd724df72b507dff6b61247d693217b97060c Mon Sep 17 00:00:00 2001 From: natec Date: Mon, 24 Sep 2001 07:48:29 +0000 Subject: [PATCH] Improved performance of split_sql_file() drasctically. git-svn-id: file:///svn/phpbb/trunk@1066 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/admin/admin_db_utilities.php | 99 ++++++++++++++---------------- 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/phpBB/admin/admin_db_utilities.php b/phpBB/admin/admin_db_utilities.php index 9133242531..269a48e81d 100644 --- a/phpBB/admin/admin_db_utilities.php +++ b/phpBB/admin/admin_db_utilities.php @@ -660,6 +660,10 @@ function output_table_content($content) function remove_remarks($sql) { $lines = explode("\n", $sql); + + // try to keep mem. use down + $sql = ""; + $linecount = count($lines); $output = ""; @@ -675,6 +679,8 @@ function remove_remarks($sql) { $output .= "\n"; } + // Trading a bit of speed for lower mem. use here. + $lines[$i] = ""; } } @@ -684,68 +690,53 @@ function remove_remarks($sql) // // split_sql_file will split an uploaded sql file into single sql statements. +// Note: expects trim() to have already been run on $sql. // function split_sql_file($sql, $delimiter) { - $sql = trim($sql); - $char = ""; - $last_char = ""; - $ret = array(); - $in_string = true; - $slashchar = 0; - - for($i = 0; $i < strlen($sql); $i++) + // Split up our string into "possible" SQL statements. + $tokens = explode($delimiter, $sql); + // try to save memory. + $sql = ""; + $output = array(); + + // we don't actually care about the matches preg gives us. + $matches = array(); + + // this is faster than calling count($oktens) every time thru the loop. + $token_count = count($tokens); + for ($i = 0; $i < $token_count; $i++) { - $char = $sql[$i]; - - // - // if delimiter found, add the parsed part to the returned array - // - if($char == $delimiter && !$in_string) + // Don't wanna add an empty string as the last thing in the array. + if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0))) { - $ret[] = substr($sql, 0, $i); - $sql = substr($sql, $i + 1); - $i = 0; - $last_char = ""; + // This is the total number of single quotes in the token. + $total_quotes = preg_match_all("/'/", $tokens[$i], $matches); + // Counts single quotes that are preceded by an odd number of backslashes, + // which means they're escaped quotes. + $escaped_quotes = preg_match_all("/(?