]> git.joonet.de Git - adminer.git/commitdiff
Remove unnecessary { } in compile
authorJakub Vrana <jakub@vrana.cz>
Wed, 16 May 2012 23:42:45 +0000 (16:42 -0700)
committerJakub Vrana <jakub@vrana.cz>
Wed, 16 May 2012 23:42:45 +0000 (16:42 -0700)
adminer/include/editing.inc.php
compile.php

index 25c8fef4cb43eb354895f7905ba9339220939433..5f0002adebfe61d12b17f8dd96dd9c29de040a4d 100644 (file)
@@ -367,7 +367,7 @@ function tar_file($filename, $contents) {
        $return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
        $checksum = 8*32; // space for checksum itself
        for ($i=0; $i < strlen($return); $i++) {
-               $checksum += ord($return{$i});
+               $checksum += ord($return[$i]);
        }
        $return .= sprintf("%06o", $checksum) . "\0 ";
        return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
index b32cd7d1c76494c18744e92decb915ee73abe079..f2710d3276c1b5a64331977255462037c853d31d 100644 (file)
@@ -84,7 +84,7 @@ function put_file_lang($match) {
 function short_identifier($number, $chars) {
        $return = '';
        while ($number >= 0) {
-               $return .= $chars{$number % strlen($chars)};
+               $return .= $chars[$number % strlen($chars)];
                $number = floor($number / strlen($chars)) - 1;
        }
        return $return;
@@ -98,6 +98,33 @@ function php_shrink($input) {
        $shortening = true;
        $tokens = token_get_all($input);
        
+       // remove unnecessary { }
+       //! change also `while () { if () {;} }` to `while () if () ;` but be careful about `if () { if () { } } else { }
+       $shorten = 0;
+       $opening = -1;
+       foreach ($tokens as $i => $token) {
+               if (in_array($token[0], array(T_IF, T_ELSE, T_ELSEIF, T_WHILE, T_DO, T_FOR, T_FOREACH), true)) {
+                       $shorten = ($token[0] == T_FOR ? 4 : 2);
+                       $opening = -1;
+               } elseif (in_array($token[0], array(T_SWITCH, T_FUNCTION, T_CLASS, T_CLOSE_TAG), true)) {
+                       $shorten = 0;
+               } elseif ($token === ';') {
+                       $shorten--;
+               } elseif ($token === '{') {
+                       if ($opening < 0) {
+                               $opening = $i;
+                       } elseif ($shorten > 1) {
+                               $shorten = 0;
+                       }
+               } elseif ($token === '}' && $opening >= 0 && $shorten == 1) {
+                       unset($tokens[$opening]);
+                       unset($tokens[$i]);
+                       $shorten = 0;
+                       $opening = -1;
+               }
+       }
+       $tokens = array_values($tokens);
+       
        foreach ($tokens as $i => $token) {
                if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
                        $short_variables[$token[1]]++;