Aerys\HPack::huffman_lookup_init PHP Method

huffman_lookup_init() private static method

(micro-)optimized decode
private static huffman_lookup_init ( )
    private static function huffman_lookup_init()
    {
        gc_disable();
        $encodingAccess = [];
        $terminals = [];
        foreach (self::HUFFMAN_CODE as $chr => $bits) {
            $len = self::HUFFMAN_CODE_LENGTHS[$chr];
            for ($bit = 0; $bit < 8; $bit++) {
                $offlen = $len + $bit;
                $next =& $encodingAccess[$bit];
                for ($byte = (int) (($offlen - 1) / 8); $byte > 0; $byte--) {
                    $cur = \str_pad(\decbin($bits >> $byte * 8 - (0x30 - $offlen) % 8 & 0xff), 8, "0", STR_PAD_LEFT);
                    if (isset($next[$cur]) && $next[$cur][0] != $encodingAccess[0]) {
                        $next =& $next[$cur][0];
                    } else {
                        $tmp =& $next;
                        unset($next);
                        $tmp[$cur] = [&$next, null];
                    }
                }
                $key = \str_pad(\decbin($bits & (1 << ($offlen - 1) % 8 + 1) - 1), ($offlen - 1) % 8 + 1, "0", STR_PAD_LEFT);
                $next[$key] = [null, $chr > 0xff ? "" : \chr($chr)];
                if ($offlen % 8) {
                    $terminals[$offlen % 8][] = [$key, &$next];
                } else {
                    $next[$key][0] =& $encodingAccess[0];
                }
            }
        }
        $memoize = [];
        for ($off = 7; $off > 0; $off--) {
            foreach ($terminals[$off] as &$terminal) {
                $key = $terminal[0];
                $next =& $terminal[1];
                if ($next[$key][0] === null) {
                    foreach ($encodingAccess[$off] as $chr => &$cur) {
                        $next[($memoize[$key] ?? ($memoize[$key] = \str_pad($key, 8, "0", STR_PAD_RIGHT))) | $chr] = [&$cur[0], $next[$key][1] != "" ? $next[$key][1] . $cur[1] : ""];
                    }
                    unset($next[$key]);
                }
            }
        }
        $memoize = [];
        for ($off = 7; $off > 0; $off--) {
            foreach ($terminals[$off] as &$terminal) {
                $next =& $terminal[1];
                foreach ($next as $k => $v) {
                    if (\strlen($k) != 1) {
                        $next[$memoize[$k] ?? ($memoize[$k] = \chr(\bindec($k)))] = $v;
                        unset($next[$k]);
                    }
                }
            }
        }
        unset($tmp, $cur, $next, $terminals, $terminal);
        gc_enable();
        gc_collect_cycles();
        return $encodingAccess[0];
    }