Minify defined functions only
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@583 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
d83b6548fb
commit
c27a8774a0
19
_compile.php
19
_compile.php
|
@ -79,24 +79,33 @@ function php_shrink($input) {
|
||||||
$special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
$special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
||||||
static $short_variables = array();
|
static $short_variables = array();
|
||||||
$shortening = true;
|
$shortening = true;
|
||||||
$special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', 'normalize_enum', '__construct'));
|
$special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', '__construct'));
|
||||||
|
$defined_functions = array();
|
||||||
static $short_functions = array();
|
static $short_functions = array();
|
||||||
$tokens = token_get_all($input);
|
$tokens = token_get_all($input);
|
||||||
|
|
||||||
foreach ($tokens as $i => $token) {
|
foreach ($tokens as $i => $token) {
|
||||||
if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
||||||
$short_variables[$token[1]]++;
|
$short_variables[$token[1]]++;
|
||||||
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !is_callable($token[1]) && !isset($special_functions[$token[1]])) {
|
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !isset($special_functions[$token[1]])) {
|
||||||
$short_functions[$token[1]]++;
|
$short_functions[$token[1]]++;
|
||||||
|
if ($tokens[$i-2][0] === T_FUNCTION) {
|
||||||
|
$defined_functions[$token[1]] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arsort($short_variables);
|
arsort($short_variables);
|
||||||
foreach (array_keys($short_variables) as $number => $key) {
|
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
|
$short_variables[$key] = short_identifier($number, implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z'))); // could use also numbers and \x7f-\xff
|
||||||
}
|
}
|
||||||
arsort($short_functions);
|
arsort($short_functions);
|
||||||
foreach (array_keys($short_functions) as $number => $key) {
|
$number = 0;
|
||||||
|
foreach ($short_functions as $key => $val) {
|
||||||
|
if (isset($defined_functions[$key])) {
|
||||||
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z')) . '_');
|
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z')) . '_');
|
||||||
|
$number++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
|
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
|
||||||
|
@ -117,11 +126,11 @@ function php_shrink($input) {
|
||||||
}
|
}
|
||||||
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
||||||
$token[1] = '$' . $short_variables[$token[1]];
|
$token[1] = '$' . $short_variables[$token[1]];
|
||||||
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !is_callable($token[1]) && !isset($special_functions[$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 && !in_array($tokens[$i-2][1], array('_result', '$_result'), true)
|
&& $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && !in_array($tokens[$i-2][1], array('_result', '$_result'), true)
|
||||||
) {
|
) {
|
||||||
$token[1] = $short_functions[$token[1]];
|
$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) && isset($short_functions[substr($token[1], 1, -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)])) {
|
||||||
$token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
|
$token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
|
||||||
}
|
}
|
||||||
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
|
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
|
||||||
|
|
|
@ -4,12 +4,12 @@ if (extension_loaded("mysqli")) {
|
||||||
var $extension = "MySQLi";
|
var $extension = "MySQLi";
|
||||||
|
|
||||||
function Min_MySQLi() {
|
function Min_MySQLi() {
|
||||||
parent::init();
|
$this->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect($server, $username, $password) {
|
function connect($server, $username, $password) {
|
||||||
list($host, $port) = explode(":", $server, 2);
|
list($host, $port) = explode(":", $server, 2);
|
||||||
return @parent::real_connect(
|
return @$this->real_connect(
|
||||||
(strlen($server) ? $host : ini_get("mysqli.default_host")),
|
(strlen($server) ? $host : ini_get("mysqli.default_host")),
|
||||||
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
|
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
|
||||||
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw")),
|
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw")),
|
||||||
|
@ -181,7 +181,7 @@ if (extension_loaded("mysqli")) {
|
||||||
set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4
|
set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4
|
||||||
parent::__construct("mysql:host=" . str_replace(":", ";port=", $server), $username, $password);
|
parent::__construct("mysql:host=" . str_replace(":", ";port=", $server), $username, $password);
|
||||||
restore_exception_handler();
|
restore_exception_handler();
|
||||||
parent::setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS
|
$this->setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS
|
||||||
$this->server_info = $this->result($this->query("SELECT VERSION()"));
|
$this->server_info = $this->result($this->query("SELECT VERSION()"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ if (extension_loaded("mysqli")) {
|
||||||
function query($query) {
|
function query($query) {
|
||||||
$_result = parent::query($query);
|
$_result = parent::query($query);
|
||||||
if (!$_result) {
|
if (!$_result) {
|
||||||
$errorInfo = parent::errorInfo();
|
$errorInfo = $this->errorInfo();
|
||||||
$this->error = $errorInfo[2];
|
$this->error = $errorInfo[2];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ if (extension_loaded("mysqli")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function escape_string($string) {
|
function escape_string($string) {
|
||||||
return substr(parent::quote($string), 1, -1);
|
return substr($this->quote($string), 1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,15 +235,15 @@ if (extension_loaded("mysqli")) {
|
||||||
var $_offset = 0, $num_rows;
|
var $_offset = 0, $num_rows;
|
||||||
|
|
||||||
function fetch_assoc() {
|
function fetch_assoc() {
|
||||||
return parent::fetch(2); // PDO::FETCH_ASSOC
|
return $this->fetch(2); // PDO::FETCH_ASSOC
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch_row() {
|
function fetch_row() {
|
||||||
return parent::fetch(3); // PDO::FETCH_NUM
|
return $this->fetch(3); // PDO::FETCH_NUM
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch_field() {
|
function fetch_field() {
|
||||||
$row = (object) parent::getColumnMeta($this->_offset++);
|
$row = (object) $this->getColumnMeta($this->_offset++);
|
||||||
$row->orgtable = $row->table;
|
$row->orgtable = $row->table;
|
||||||
$row->orgname = $row->name;
|
$row->orgname = $row->name;
|
||||||
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
|
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -10,3 +10,4 @@ Function to fix database encoding - http://php.vrana.cz/prevod-kodovani-mysql.ph
|
||||||
? Execution time in sql.inc.php
|
? Execution time in sql.inc.php
|
||||||
? Save token also to cookie - for session expiration and login in other window
|
? Save token also to cookie - for session expiration and login in other window
|
||||||
? Save uploaded files after error to session variable instead of hidden field
|
? Save uploaded files after error to session variable instead of hidden field
|
||||||
|
? Aliasing of built-in functions can save 7 KB, substitution of $_GET and friends can save 2 KB, remove of base64_decode() + using chars 127-255 in minification can save 1 KB
|
||||||
|
|
Loading…
Reference in a new issue