Permalink
Browse files

Size reduction by minification of variables

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@579 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent e8f1ddc commit a06f4c1521d0ae44cb8f596bbf36dbf32f4036a8 jakubvrana committed Apr 15, 2009
Showing with 27 additions and 0 deletions.
  1. +26 −0 _compile.php
  2. +1 −0 changes.txt
View
@@ -65,8 +65,22 @@ function put_file($match) {
return $return;
}
+function short_variable($number) {
+ $chars = implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z')); // could use also numbers and \x7f-\xff
+ $return = '$';
+ while ($number >= 0) {
+ $return .= $chars{$number % strlen($chars)};
+ $number = floor($number / strlen($chars)) - 1;
+ }
+ return $return;
+}
+
// Dgx's PHP shrinker
function php_shrink($input) {
+ $special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
+ static $short_variables = array();
+ $shortening = true;
+
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
$space = '';
$output = '';
@@ -77,6 +91,18 @@ function php_shrink($input) {
if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE) {
$space = "\n";
} else {
+ if ($token[0] == T_VAR) {
+ $shortening = false;
+ } elseif (!$shortening) {
+ if ($token[1] == ';') {
+ $shortening = true;
+ }
+ } elseif ($token[0] == T_VARIABLE && !isset($special_variables[$token[1]])) {
+ if (!isset($short_variables[$token[1]])) {
+ $short_variables[$token[1]] = short_variable(count($short_variables));
+ }
+ $token[1] = $short_variables[$token[1]];
+ }
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
$space = '';
}
View
@@ -7,6 +7,7 @@ Cross links to select and table (bug #2236232), link new item
Suhosin compatibility (thanks to Klemens Hackel)
Remove max_allowed_packet from export
Read style from phpMinAdmin.css if exists
+Size reduction by minification of variables
phpMinAdmin 1.9.1:
Update translations

0 comments on commit a06f4c1

Please sign in to comment.