From 53f9d89fbd7c246d424d9d696a4781ef41a66064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Aug 2011 16:59:31 +0200 Subject: [PATCH 1/6] Wrap some long lines --- libraries/sqlparser.lib.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index fba27194af..c3388e750e 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -206,7 +206,8 @@ if (! defined('PMA_MINIMUM_COMMON')) { */ function PMA_SQP_parse($sql) { - static $PMA_SQPdata_column_attrib, $PMA_SQPdata_reserved_word, $PMA_SQPdata_column_type; + static $PMA_SQPdata_column_attrib, $PMA_SQPdata_reserved_word; + static $PMA_SQPdata_column_type; static $PMA_SQPdata_function_name, $PMA_SQPdata_forbidden_word; global $mysql_charsets, $mysql_collations_flat; @@ -221,11 +222,21 @@ if (! defined('PMA_MINIMUM_COMMON')) { // Create local hashtables if (!isset($PMA_SQPdata_column_attrib_cnt)) { - $PMA_SQPdata_column_attrib = array_flip($GLOBALS['PMA_SQPdata_column_attrib']); - $PMA_SQPdata_function_name = array_flip($GLOBALS['PMA_SQPdata_function_name']); - $PMA_SQPdata_reserved_word = array_flip($GLOBALS['PMA_SQPdata_reserved_word']); - $PMA_SQPdata_forbidden_word = array_flip($GLOBALS['PMA_SQPdata_forbidden_word']); - $PMA_SQPdata_column_type = array_flip($GLOBALS['PMA_SQPdata_column_type']); + $PMA_SQPdata_column_attrib = array_flip( + $GLOBALS['PMA_SQPdata_column_attrib'] + ); + $PMA_SQPdata_function_name = array_flip( + $GLOBALS['PMA_SQPdata_function_name'] + ); + $PMA_SQPdata_reserved_word = array_flip( + $GLOBALS['PMA_SQPdata_reserved_word'] + ); + $PMA_SQPdata_forbidden_word = array_flip( + $GLOBALS['PMA_SQPdata_forbidden_word'] + ); + $PMA_SQPdata_column_type = array_flip( + $GLOBALS['PMA_SQPdata_column_type'] + ); } $sql_array = array(); From 3228a5b761c0a2d48b79175f6527142cc10b9f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Aug 2011 17:05:03 +0200 Subject: [PATCH 2/6] Avoid using GLOBALS referenced functions This actually makes performance because it needs extra lookup in globals. --- libraries/sqlparser.lib.php | 66 ++++++++++++++++++------------------- libraries/string.lib.php | 2 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index c3388e750e..1037ca318c 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -281,7 +281,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $this_was_quote = false; while ($count2 < $len) { - $c = $GLOBALS['PMA_substr']($sql, $count2, 1); + $c = PMA_substr($sql, $count2, 1); $count1 = $count2; $previous_was_space = $this_was_space; @@ -303,7 +303,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { } // Checks for white space - if ($GLOBALS['PMA_STR_isSpace']($c)) { + if (PMA_STR_isSpace($c)) { $this_was_space = true; $count2++; continue; @@ -314,9 +314,9 @@ if (! defined('PMA_MINIMUM_COMMON')) { // C style /* */ // ANSI style -- if (($c == '#') - || (($count2 + 1 < $len) && ($c == '/') && ($GLOBALS['PMA_substr']($sql, $count2 + 1, 1) == '*')) - || (($count2 + 2 == $len) && ($c == '-') && ($GLOBALS['PMA_substr']($sql, $count2 + 1, 1) == '-')) - || (($count2 + 2 < $len) && ($c == '-') && ($GLOBALS['PMA_substr']($sql, $count2 + 1, 1) == '-') && (($GLOBALS['PMA_substr']($sql, $count2 + 2, 1) <= ' ')))) { + || (($count2 + 1 < $len) && ($c == '/') && (PMA_substr($sql, $count2 + 1, 1) == '*')) + || (($count2 + 2 == $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-')) + || (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) <= ' ')))) { $count2++; $pos = 0; $type = 'bad'; @@ -325,24 +325,24 @@ if (! defined('PMA_MINIMUM_COMMON')) { $type = 'mysql'; case '-': $type = 'ansi'; - $pos = $GLOBALS['PMA_strpos']($sql, "\n", $count2); + $pos = PMA_strpos($sql, "\n", $count2); break; case '/': $type = 'c'; - $pos = $GLOBALS['PMA_strpos']($sql, '*/', $count2); + $pos = PMA_strpos($sql, '*/', $count2); $pos += 2; break; default: break; } // end switch $count2 = ($pos < $count2) ? $len : $pos; - $str = $GLOBALS['PMA_substr']($sql, $count1, $count2 - $count1); + $str = PMA_substr($sql, $count1, $count2 - $count1); PMA_SQP_arrayAdd($sql_array, 'comment_' . $type, $str, $arraysize); continue; } // end if // Checks for something inside quotation marks - if ($GLOBALS['PMA_strpos']($quote_list, $c) !== false) { + if (PMA_strpos($quote_list, $c) !== false) { $startquotepos = $count2; $quotetype = $c; $count2++; @@ -352,7 +352,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $oldpos = 0; do { $oldpos = $pos; - $pos = $GLOBALS['PMA_strpos'](' ' . $sql, $quotetype, $oldpos + 1) - 1; + $pos = PMA_strpos(' ' . $sql, $quotetype, $oldpos + 1) - 1; // ($pos === false) if ($pos < 0) { if ($c == '`') { @@ -366,7 +366,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { * * SELECT * FROM `table` */ - $pos_quote_separator = $GLOBALS['PMA_strpos'](' ' . $sql, $GLOBALS['sql_delimiter'], $oldpos + 1) - 1; + $pos_quote_separator = PMA_strpos(' ' . $sql, $GLOBALS['sql_delimiter'], $oldpos + 1) - 1; if ($pos_quote_separator < 0) { $len += 1; $sql .= '`'; @@ -374,7 +374,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $pos = $len; } else { $len += 1; - $sql = $GLOBALS['PMA_substr']($sql, 0, $pos_quote_separator) . '`' . $GLOBALS['PMA_substr']($sql, $pos_quote_separator); + $sql = PMA_substr($sql, 0, $pos_quote_separator) . '`' . PMA_substr($sql, $pos_quote_separator); $sql_array['raw'] = $sql; $pos = $pos_quote_separator; } @@ -400,7 +400,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { if (($pos < $len) && PMA_STR_charIsEscaped($sql, $pos) && $c != '`') { $pos ++; continue; - } elseif (($pos + 1 < $len) && ($GLOBALS['PMA_substr']($sql, $pos, 1) == $quotetype) && ($GLOBALS['PMA_substr']($sql, $pos + 1, 1) == $quotetype)) { + } elseif (($pos + 1 < $len) && (PMA_substr($sql, $pos, 1) == $quotetype) && (PMA_substr($sql, $pos + 1, 1) == $quotetype)) { $pos = $pos + 2; continue; } else { @@ -427,27 +427,27 @@ if (! defined('PMA_MINIMUM_COMMON')) { default: break; } // end switch - $data = $GLOBALS['PMA_substr']($sql, $count1, $count2 - $count1); + $data = PMA_substr($sql, $count1, $count2 - $count1); PMA_SQP_arrayAdd($sql_array, $type, $data, $arraysize); continue; } // Checks for brackets - if ($GLOBALS['PMA_strpos']($bracket_list, $c) !== false) { + if (PMA_strpos($bracket_list, $c) !== false) { // All bracket tokens are only one item long $this_was_bracket = true; $count2++; $type_type = ''; - if ($GLOBALS['PMA_strpos']('([{', $c) !== false) { + if (PMA_strpos('([{', $c) !== false) { $type_type = 'open'; } else { $type_type = 'close'; } $type_style = ''; - if ($GLOBALS['PMA_strpos']('()', $c) !== false) { + if (PMA_strpos('()', $c) !== false) { $type_style = 'round'; - } elseif ($GLOBALS['PMA_strpos']('[]', $c) !== false) { + } elseif (PMA_strpos('[]', $c) !== false) { $type_style = 'square'; } else { $type_style = 'curly'; @@ -474,7 +474,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { if (PMA_STR_isSqlIdentifier($c, false) || $c == '@' || ($c == '.' - && $GLOBALS['PMA_STR_isDigit']($GLOBALS['PMA_substr']($sql, $count2 + 1, 1)) + && PMA_STR_isDigit(PMA_substr($sql, $count2 + 1, 1)) && ($previous_was_space || $previous_was_bracket || $previous_was_listsep))) { /* DEBUG @@ -492,8 +492,8 @@ if (! defined('PMA_MINIMUM_COMMON')) { $is_identifier = $previous_was_punct; $is_sql_variable = $c == '@' && ! $previous_was_quote; $is_user = $c == '@' && $previous_was_quote; - $is_digit = !$is_identifier && !$is_sql_variable && $GLOBALS['PMA_STR_isDigit']($c); - $is_hex_digit = $is_digit && $c == '0' && $count2 < $len && $GLOBALS['PMA_substr']($sql, $count2, 1) == 'x'; + $is_digit = !$is_identifier && !$is_sql_variable && PMA_STR_isDigit($c); + $is_hex_digit = $is_digit && $c == '0' && $count2 < $len && PMA_substr($sql, $count2, 1) == 'x'; $is_float_digit = $c == '.'; $is_float_digit_exponent = false; @@ -522,8 +522,8 @@ if (! defined('PMA_MINIMUM_COMMON')) { unset($pos); } - while (($count2 < $len) && PMA_STR_isSqlIdentifier($GLOBALS['PMA_substr']($sql, $count2, 1), ($is_sql_variable || $is_digit))) { - $c2 = $GLOBALS['PMA_substr']($sql, $count2, 1); + while (($count2 < $len) && PMA_STR_isSqlIdentifier(PMA_substr($sql, $count2, 1), ($is_sql_variable || $is_digit))) { + $c2 = PMA_substr($sql, $count2, 1); if ($is_sql_variable && ($c2 == '.')) { $count2++; continue; @@ -551,7 +551,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $is_float_digit = false; } } - if (($is_hex_digit && PMA_STR_isHexDigit($c2)) || ($is_digit && $GLOBALS['PMA_STR_isDigit']($c2))) { + if (($is_hex_digit && PMA_STR_isHexDigit($c2)) || ($is_digit && PMA_STR_isDigit($c2))) { $count2++; continue; } else { @@ -563,7 +563,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { } // end while $l = $count2 - $count1; - $str = $GLOBALS['PMA_substr']($sql, $count1, $l); + $str = PMA_substr($sql, $count1, $l); $type = ''; if ($is_digit || $is_float_digit || $is_hex_digit) { @@ -588,15 +588,15 @@ if (! defined('PMA_MINIMUM_COMMON')) { } // Checks for punct - if ($GLOBALS['PMA_strpos']($allpunct_list, $c) !== false) { - while (($count2 < $len) && $GLOBALS['PMA_strpos']($allpunct_list, $GLOBALS['PMA_substr']($sql, $count2, 1)) !== false) { + if (PMA_strpos($allpunct_list, $c) !== false) { + while (($count2 < $len) && PMA_strpos($allpunct_list, PMA_substr($sql, $count2, 1)) !== false) { $count2++; } $l = $count2 - $count1; if ($l == 1) { $punct_data = $c; } else { - $punct_data = $GLOBALS['PMA_substr']($sql, $count1, $l); + $punct_data = PMA_substr($sql, $count1, $l); } // Special case, sometimes, althought two characters are @@ -638,12 +638,12 @@ if (! defined('PMA_MINIMUM_COMMON')) { if (($first == ',') || ($first == ';') || ($first == '.') || ($first == '*')) { $count2 = $count1 + 1; $punct_data = $first; - } elseif (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || $GLOBALS['PMA_substr']($sql, $count2, 1) <= ' '))) { + } elseif (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || PMA_substr($sql, $count2, 1) <= ' '))) { $count2 -= 2; - $punct_data = $GLOBALS['PMA_substr']($sql, $count1, $count2 - $count1); + $punct_data = PMA_substr($sql, $count1, $count2 - $count1); } elseif (($last == '-') || ($last == '+') || ($last == '!')) { $count2--; - $punct_data = $GLOBALS['PMA_substr']($sql, $count1, $count2 - $count1); + $punct_data = PMA_substr($sql, $count1, $count2 - $count1); /** * @todo for negation operator, split in 2 tokens ? * "select x&~1 from t" @@ -666,7 +666,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $count2++; $debugstr = 'C1 C2 LEN: ' . $count1 . ' ' . $count2 . ' ' . $len . "\n" - . 'STR: ' . $GLOBALS['PMA_substr']($sql, $count1, $count2 - $count1) . "\n"; + . 'STR: ' . PMA_substr($sql, $count1, $count2 - $count1) . "\n"; PMA_SQP_bug($debugstr, $sql); return $sql_array; @@ -2073,7 +2073,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { */ function PMA_SQP_formatHtml_colorize($arr) { - $i = $GLOBALS['PMA_strpos']($arr['type'], '_'); + $i = PMA_strpos($arr['type'], '_'); $class = ''; if ($i > 0) { $class = 'syntax_' . PMA_substr($arr['type'], 0, $i) . ' '; diff --git a/libraries/string.lib.php b/libraries/string.lib.php index 0cfef414cb..2f292fc593 100644 --- a/libraries/string.lib.php +++ b/libraries/string.lib.php @@ -107,7 +107,7 @@ function PMA_STR_numberInRangeInclusive($num, $lower, $upper) */ function PMA_STR_isSqlIdentifier($c, $dot_is_valid = false) { - return ($GLOBALS['PMA_STR_isAlnum']($c) + return (PMA_STR_isAlnum($c) || ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249 || $c == '_' || $c == '$' From 3d29edba96358b6ac5f494332975bb092a2b10b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Aug 2011 17:10:31 +0200 Subject: [PATCH 3/6] Remove no longer needed globals --- libraries/string.lib.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libraries/string.lib.php b/libraries/string.lib.php index 2f292fc593..b2cc6d95be 100644 --- a/libraries/string.lib.php +++ b/libraries/string.lib.php @@ -30,12 +30,8 @@ if ($GLOBALS['PMA_allow_mbstr']) { * Load proper code for handling input. */ if ($GLOBALS['PMA_allow_mbstr']) { - $GLOBALS['PMA_strpos'] = 'mb_strpos'; - $GLOBALS['PMA_substr'] = 'mb_substr'; require './libraries/string_mb.lib.php'; } else { - $GLOBALS['PMA_strpos'] = 'strpos'; - $GLOBALS['PMA_substr'] = 'substr'; require './libraries/string_native.lib.php'; } @@ -43,14 +39,8 @@ if ($GLOBALS['PMA_allow_mbstr']) { * Load ctype handler. */ if ($GLOBALS['PMA_allow_ctype']) { - $GLOBALS['PMA_STR_isAlnum'] = 'ctype_alnum'; - $GLOBALS['PMA_STR_isDigit'] = 'ctype_digit'; - $GLOBALS['PMA_STR_isSpace'] = 'ctype_space'; require './libraries/string_type_ctype.lib.php'; } else { - $GLOBALS['PMA_STR_isAlnum'] = 'PMA_STR_isAlnum'; - $GLOBALS['PMA_STR_isDigit'] = 'PMA_STR_isDigit'; - $GLOBALS['PMA_STR_isSpace'] = 'PMA_STR_isSpace'; require './libraries/string_type_native.lib.php'; } From 2bfaa716bdb3e9e4cfa6d0a85a321328ffd7161f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Aug 2011 17:12:19 +0200 Subject: [PATCH 4/6] Remove global variables These are used only once anyway and storing in variables looks like it is configurable. --- libraries/string.lib.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libraries/string.lib.php b/libraries/string.lib.php index b2cc6d95be..0e9f974347 100644 --- a/libraries/string.lib.php +++ b/libraries/string.lib.php @@ -19,17 +19,11 @@ if (! defined('PHPMYADMIN')) { exit; } -$GLOBALS['PMA_allow_mbstr'] = @function_exists('mb_strlen'); -$GLOBALS['PMA_allow_ctype'] = @extension_loaded('ctype'); - -if ($GLOBALS['PMA_allow_mbstr']) { - mb_internal_encoding('utf-8'); -} - /** * Load proper code for handling input. */ -if ($GLOBALS['PMA_allow_mbstr']) { +if (@function_exists('mb_strlen')) { + mb_internal_encoding('utf-8'); require './libraries/string_mb.lib.php'; } else { require './libraries/string_native.lib.php'; @@ -38,7 +32,7 @@ if ($GLOBALS['PMA_allow_mbstr']) { /** * Load ctype handler. */ -if ($GLOBALS['PMA_allow_ctype']) { +if (@extension_loaded('ctype')) { require './libraries/string_type_ctype.lib.php'; } else { require './libraries/string_type_native.lib.php'; From aceefcb23e02daa5d4d4e357f0f6666661e7b879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Aug 2011 17:15:59 +0200 Subject: [PATCH 5/6] Avoid three calls of same PMA_substr --- libraries/sqlparser.lib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 1037ca318c..d26c4607c3 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -313,10 +313,11 @@ if (! defined('PMA_MINIMUM_COMMON')) { // MySQL style # // C style /* */ // ANSI style -- + $next_c = PMA_substr($sql, $count2 + 1, 1); if (($c == '#') - || (($count2 + 1 < $len) && ($c == '/') && (PMA_substr($sql, $count2 + 1, 1) == '*')) - || (($count2 + 2 == $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-')) - || (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) <= ' ')))) { + || (($count2 + 1 < $len) && ($c == '/') && ($next_c == '*')) + || (($count2 + 2 == $len) && ($c == '-') && ($next_c == '-')) + || (($count2 + 2 < $len) && ($c == '-') && ($next_c == '-') && ((PMA_substr($sql, $count2 + 2, 1) <= ' ')))) { $count2++; $pos = 0; $type = 'bad'; From f5cdef3db8fe356f5bedbd8a0372c436e653aff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 8 Aug 2011 17:17:34 +0200 Subject: [PATCH 6/6] No need to mention requirements --- libraries/sqlparser.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index d26c4607c3..9a6df66f59 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -507,7 +507,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { echo ''; */ - // Nijel: Fast skip is especially needed for huge BLOB data, requires PHP at least 4.3.0: + // Fast skip is especially needed for huge BLOB data if ($is_hex_digit) { $count2++; $pos = strspn($sql, '0123456789abcdefABCDEF', $count2);