Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minify defined functions only

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@583 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
commit c27a8774a0925650e8cedf0966b8a77494219df8 1 parent d83b654
jakubvrana authored
Showing with 24 additions and 14 deletions.
  1. +15 −6 _compile.php
  2. +8 −8 abstraction.inc.php
  3. +1 −0  todo.txt
21 _compile.php
View
@@ -79,24 +79,33 @@ function php_shrink($input) {
$special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
static $short_variables = array();
$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();
$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] === '(' && !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]]++;
+ if ($tokens[$i-2][0] === T_FUNCTION) {
+ $defined_functions[$token[1]] = true;
+ }
}
}
+
arsort($short_variables);
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);
- foreach (array_keys($short_functions) as $number => $key) {
- $short_functions[$key] = short_identifier($number, implode("", range('a', 'z')) . '_');
+ $number = 0;
+ foreach ($short_functions as $key => $val) {
+ if (isset($defined_functions[$key])) {
+ $short_functions[$key] = short_identifier($number, implode("", range('a', 'z')) . '_');
+ $number++;
+ }
}
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
@@ -117,11 +126,11 @@ 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] === '(' && !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)
) {
$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)] . "'";
}
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
16 abstraction.inc.php
View
@@ -4,12 +4,12 @@ class Min_MySQLi extends MySQLi {
var $extension = "MySQLi";
function Min_MySQLi() {
- parent::init();
+ $this->init();
}
function connect($server, $username, $password) {
list($host, $port) = explode(":", $server, 2);
- return @parent::real_connect(
+ return @$this->real_connect(
(strlen($server) ? $host : ini_get("mysqli.default_host")),
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw")),
@@ -181,7 +181,7 @@ function connect($server, $username, $password) {
set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4
parent::__construct("mysql:host=" . str_replace(":", ";port=", $server), $username, $password);
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()"));
return true;
}
@@ -193,7 +193,7 @@ function select_db($database) {
function query($query) {
$_result = parent::query($query);
if (!$_result) {
- $errorInfo = parent::errorInfo();
+ $errorInfo = $this->errorInfo();
$this->error = $errorInfo[2];
return false;
}
@@ -227,7 +227,7 @@ function result($_result, $field = 0) {
}
function escape_string($string) {
- return substr(parent::quote($string), 1, -1);
+ return substr($this->quote($string), 1, -1);
}
}
@@ -235,15 +235,15 @@ class Min_PDOStatement extends PDOStatement {
var $_offset = 0, $num_rows;
function fetch_assoc() {
- return parent::fetch(2); // PDO::FETCH_ASSOC
+ return $this->fetch(2); // PDO::FETCH_ASSOC
}
function fetch_row() {
- return parent::fetch(3); // PDO::FETCH_NUM
+ return $this->fetch(3); // PDO::FETCH_NUM
}
function fetch_field() {
- $row = (object) parent::getColumnMeta($this->_offset++);
+ $row = (object) $this->getColumnMeta($this->_offset++);
$row->orgtable = $row->table;
$row->orgname = $row->name;
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
1  todo.txt
View
@@ -10,3 +10,4 @@ Function to fix database encoding - http://php.vrana.cz/prevod-kodovani-mysql.ph
? Execution time in sql.inc.php
? 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
+? 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
Please sign in to comment.
Something went wrong with that request. Please try again.