]> git.joonet.de Git - adminer.git/commitdiff
Size reduction by minification of variables
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 15 Apr 2009 11:23:31 +0000 (11:23 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 15 Apr 2009 11:23:31 +0000 (11:23 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@579 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
changes.txt

index 7651ed0df8ee13ea9d558097e23306e239f0781f..72e8899e45ff9d9e82cb5772ae58ce15009210fc 100644 (file)
@@ -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 = '';
                        }
index c091d3d2a350b6b2ae1f9e74ca41de48995778ce..6697bd60317cff635a8c3147782817c788f9659e 100644 (file)
@@ -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