From 90a6bd8d4b1af6584937831d148b65a073bda9c1 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Mon, 27 Jul 2009 10:12:23 +0000 Subject: [PATCH] Remove function minification for performance and customization git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@912 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/include/functions.inc.php | 1 - adminer/include/mysql.inc.php | 54 ++----------------------------- adminer/select.inc.php | 2 +- compile.php | 27 ---------------- 4 files changed, 3 insertions(+), 81 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 0f6d4dab..70ff66ae 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -365,7 +365,6 @@ function email_header($header) { } function call_adminer($method, $default, $arg1 = null, $arg2 = null, $arg3 = null) { - // maintains original method name in minification if (method_exists('Adminer', $method)) { // user defined class // can use func_get_args() and call_user_func_array() return Adminer::$method($arg1, $arg2, $arg3); diff --git a/adminer/include/mysql.inc.php b/adminer/include/mysql.inc.php index a4377651..37d7724d 100644 --- a/adminer/include/mysql.inc.php +++ b/adminer/include/mysql.inc.php @@ -24,63 +24,13 @@ if (extension_loaded("mysqli")) { if (!$result) { return false; } - $row = $result->_result->fetch_array(); + $row = $result->fetch_array(); return $row[$field]; } function quote($string) { - return "'" . parent::escape_string($string) . "'"; + return "'" . $this->escape_string($string) . "'"; } - - // minification compatibility start - function select_db($database) { - return parent::select_db($database); - } - - function query($query) { - // result is packed in envelope object to allow minification - $result = parent::query($query); - return (is_object($result) ? new Min_Result($result) : $result); - } - - function multi_query($query) { - return parent::multi_query($query); - } - - function store_result() { - $result = parent::store_result(); - return (is_object($result) ? new Min_Result($result) : $result); - } - - function next_result() { - return parent::next_result(); - } - } - - class Min_Result { - var $_result, $num_rows; - - function __construct($result) { - $this->_result = $result; - $this->num_rows = $result->num_rows; - } - - function fetch_assoc() { - return $this->_result->fetch_assoc(); - } - - function fetch_row() { - return $this->_result->fetch_row(); - } - - function fetch_field() { - return $this->_result->fetch_field(); - } - - function free() { - return $this->_result->free(); - } - // minification compatibility end } } elseif (extension_loaded("mysql")) { diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 14f1c8ac..7d396f61 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -381,7 +381,7 @@ if (!$columns) { } echo "
" . lang('CSV Import') . "
\n"; - adminer_select_extra_display(array_filter($email_fields)); //! should use strlen but compile.php doesn't support array_filter + adminer_select_extra_display(array_filter($email_fields, 'strlen')); echo "\n"; } diff --git a/compile.php b/compile.php index a2a670f8..bc1681d7 100644 --- a/compile.php +++ b/compile.php @@ -80,20 +80,12 @@ function short_identifier($number, $chars) { function php_shrink($input) { $special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER')); static $short_variables = array(); - static $short_functions = array(); $shortening = true; - $special_functions = array_flip(array('Min_DB', 'Min_Result', '__construct')); - $defined_functions = array(); $tokens = token_get_all($input); foreach ($tokens as $i => $token) { if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) { $short_variables[$token[1]]++; - } elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !isset($special_functions[$token[1]])) { - $short_functions[$token[1]]++; - if ($tokens[$i-2][0] === T_FUNCTION) { - $defined_functions[$token[1]] = true; - } } } @@ -101,16 +93,6 @@ function php_shrink($input) { foreach (array_keys($short_variables) as $number => $key) { $short_variables[$key] = short_identifier($number, implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z'))); // could use also numbers and \x7f-\xff } - arsort($short_functions); - $number = 0; - foreach ($short_functions as $key => $val) { - if (isset($defined_functions[$key])) { - do { - $short_functions[$key] = short_identifier($number, implode("", range('a', 'z'))); // _ not used to not collide with gettext() - $number++; - } while (isset($short_functions[$short_functions[$key]])); // don't overwrite existing functions - } - } $set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}')); $space = ''; @@ -145,15 +127,6 @@ function php_shrink($input) { } } elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) { $token[1] = '$' . $short_variables[$token[1]]; - } elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && isset($defined_functions[$token[1]]) - && $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && $tokens[$i-2][1] !== '_result' // don't substitute parent methods - used to link PHP methods only - ) { - $token[1] = $short_functions[$token[1]]; - } elseif ($token[0] == T_CONSTANT_ENCAPSED_STRING - && (($tokens[$i-1] === '(' && in_array($tokens[$i-2][1], array('array_map', 'set_exception_handler'), true)) || $token[1] == "'normalize_enum'") - && isset($defined_functions[substr($token[1], 1, -1)]) - ) { // minify callback functions too - $token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'"; } if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) { $space = '';