From a06f4c1521d0ae44cb8f596bbf36dbf32f4036a8 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Wed, 15 Apr 2009 11:23:31 +0000 Subject: [PATCH] Size reduction by minification of variables git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@579 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- _compile.php | 26 ++++++++++++++++++++++++++ changes.txt | 1 + 2 files changed, 27 insertions(+) diff --git a/_compile.php b/_compile.php index 7651ed0d..72e8899e 100644 --- a/_compile.php +++ b/_compile.php @@ -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 = ''; } diff --git a/changes.txt b/changes.txt index c091d3d2..6697bd60 100644 --- a/changes.txt +++ b/changes.txt @@ -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