Fix some ugly compound literals.

This commit is contained in:
Andy Balholm 2020-05-08 15:14:47 -07:00
parent b2497e8d72
commit 4b2775ea5e
1 changed files with 56 additions and 519 deletions

575
encode.go
View File

@ -217,332 +217,6 @@ func encodeWindowBits(lgwin int, large_window bool, last_bytes *uint16, last_byt
} }
} }
/* Initializes the command and distance prefix codes for the first block. */
var initCommandPrefixCodes_kDefaultCommandDepths = [128]byte{
0,
4,
4,
5,
6,
6,
7,
7,
7,
7,
7,
8,
8,
8,
8,
8,
0,
0,
0,
4,
4,
4,
4,
4,
5,
5,
6,
6,
6,
6,
7,
7,
7,
7,
10,
10,
10,
10,
10,
10,
0,
4,
4,
5,
5,
5,
6,
6,
7,
8,
8,
9,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
5,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
6,
6,
6,
6,
6,
6,
5,
5,
5,
5,
5,
5,
4,
4,
4,
4,
4,
4,
4,
5,
5,
5,
5,
5,
5,
6,
6,
7,
7,
7,
8,
10,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
}
var initCommandPrefixCodes_kDefaultCommandBits = [128]uint16{
0,
0,
8,
9,
3,
35,
7,
71,
39,
103,
23,
47,
175,
111,
239,
31,
0,
0,
0,
4,
12,
2,
10,
6,
13,
29,
11,
43,
27,
59,
87,
55,
15,
79,
319,
831,
191,
703,
447,
959,
0,
14,
1,
25,
5,
21,
19,
51,
119,
159,
95,
223,
479,
991,
63,
575,
127,
639,
383,
895,
255,
767,
511,
1023,
14,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
27,
59,
7,
39,
23,
55,
30,
1,
17,
9,
25,
5,
0,
8,
4,
12,
2,
10,
6,
21,
13,
29,
3,
19,
11,
15,
47,
31,
95,
63,
127,
255,
767,
2815,
1791,
3839,
511,
2559,
1535,
3583,
1023,
3071,
2047,
4095,
}
var initCommandPrefixCodes_kDefaultCommandCode = []byte{
0xff,
0x77,
0xd5,
0xbf,
0xe7,
0xde,
0xea,
0x9e,
0x51,
0x5d,
0xde,
0xc6,
0x70,
0x57,
0xbc,
0x58,
0x58,
0x58,
0xd8,
0xd8,
0x58,
0xd5,
0xcb,
0x8c,
0xea,
0xe0,
0xc3,
0x87,
0x1f,
0x83,
0xc1,
0x60,
0x1c,
0x67,
0xb2,
0xaa,
0x06,
0x83,
0xc1,
0x60,
0x30,
0x18,
0xcc,
0xa1,
0xce,
0x88,
0x54,
0x94,
0x46,
0xe1,
0xb0,
0xd0,
0x4e,
0xb2,
0xf7,
0x04,
0x00,
}
var initCommandPrefixCodes_kDefaultCommandCodeNumBits uint = 448
func initCommandPrefixCodes(cmd_depths []byte, cmd_bits []uint16, cmd_code []byte, cmd_code_numbits *uint) {
copy(cmd_depths, initCommandPrefixCodes_kDefaultCommandDepths[:])
copy(cmd_bits, initCommandPrefixCodes_kDefaultCommandBits[:])
/* Initialize the pre-compressed form of the command and distance prefix
codes. */
copy(cmd_code, initCommandPrefixCodes_kDefaultCommandCode)
*cmd_code_numbits = initCommandPrefixCodes_kDefaultCommandCodeNumBits
}
/* Decide about the context map based on the ability of the prediction /* Decide about the context map based on the ability of the prediction
ability of the previous byte UTF8-prefix on the next byte. The ability of the previous byte UTF8-prefix on the next byte. The
prediction ability is calculated as Shannon entropy. Here we need prediction ability is calculated as Shannon entropy. Here we need
@ -552,136 +226,16 @@ func initCommandPrefixCodes(cmd_depths []byte, cmd_bits []uint16, cmd_code []byt
coding. */ coding. */
var kStaticContextMapContinuation = [64]uint32{ var kStaticContextMapContinuation = [64]uint32{
1, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
} }
var kStaticContextMapSimpleUTF8 = [64]uint32{ var kStaticContextMapSimpleUTF8 = [64]uint32{
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
} }
func chooseContextMap(quality int, bigram_histo []uint32, num_literal_contexts *uint, literal_context_map *[]uint32) { func chooseContextMap(quality int, bigram_histo []uint32, num_literal_contexts *uint, literal_context_map *[]uint32) {
@ -733,70 +287,22 @@ func chooseContextMap(quality int, bigram_histo []uint32, num_literal_contexts *
first 5 bits of literals. */ first 5 bits of literals. */
var kStaticContextMapComplexUTF8 = [64]uint32{ var kStaticContextMapComplexUTF8 = [64]uint32{
11, 11, 11, 12, 12, /* 0 special */
11, 0, 0, 0, 0, /* 4 lf */
12, 1, 1, 9, 9, /* 8 space */
12, 2, 2, 2, 2, /* !, first after space/lf and after something else. */
0, 1, 1, 1, 1, /* " */
0, 8, 3, 3, 3, /* % */
0, 1, 1, 1, 1, /* ({[ */
0, 2, 2, 2, 2, /* }]) */
1, 8, 4, 4, 4, /* :; */
1, 8, 7, 4, 4, /* . */
9, 8, 0, 0, 0, /* > */
9, 3, 3, 3, 3, /* [0..9] */
2, 5, 5, 10, 5, /* [A-Z] */
2, 5, 5, 10, 5,
2, 6, 6, 6, 6, /* [a-z] */
2, 6, 6, 6, 6,
1,
1,
1,
1,
8,
3,
3,
3,
1,
1,
1,
1,
2,
2,
2,
2,
8,
4,
4,
4,
8,
7,
4,
4,
8,
0,
0,
0,
3,
3,
3,
3,
5,
5,
10,
5,
5,
5,
10,
5,
6,
6,
6,
6,
6,
6,
6,
6,
} }
func shouldUseComplexStaticContextMap(input []byte, start_pos uint, length uint, mask uint, quality int, size_hint uint, num_literal_contexts *uint, literal_context_map *[]uint32) bool { func shouldUseComplexStaticContextMap(input []byte, start_pos uint, length uint, mask uint, quality int, size_hint uint, num_literal_contexts *uint, literal_context_map *[]uint32) bool {
@ -1051,7 +557,38 @@ func ensureInitialized(s *Writer) bool {
} }
if s.params.quality == fastOnePassCompressionQuality { if s.params.quality == fastOnePassCompressionQuality {
initCommandPrefixCodes(s.cmd_depths_[:], s.cmd_bits_[:], s.cmd_code_[:], &s.cmd_code_numbits_) s.cmd_depths_ = [128]byte{
0, 4, 4, 5, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
0, 0, 0, 4, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7,
7, 7, 10, 10, 10, 10, 10, 10, 0, 4, 4, 5, 5, 5, 6, 6,
7, 8, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4,
4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 8, 10,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
}
s.cmd_bits_ = [128]uint16{
0, 0, 8, 9, 3, 35, 7, 71,
39, 103, 23, 47, 175, 111, 239, 31,
0, 0, 0, 4, 12, 2, 10, 6,
13, 29, 11, 43, 27, 59, 87, 55,
15, 79, 319, 831, 191, 703, 447, 959,
0, 14, 1, 25, 5, 21, 19, 51,
119, 159, 95, 223, 479, 991, 63, 575,
127, 639, 383, 895, 255, 767, 511, 1023,
14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27, 59, 7, 39, 23, 55, 30, 1, 17, 9, 25, 5, 0, 8, 4, 12,
2, 10, 6, 21, 13, 29, 3, 19, 11, 15, 47, 31, 95, 63, 127, 255,
767, 2815, 1791, 3839, 511, 2559, 1535, 3583, 1023, 3071, 2047, 4095,
}
s.cmd_code_ = [512]byte{
0xff, 0x77, 0xd5, 0xbf, 0xe7, 0xde, 0xea, 0x9e, 0x51, 0x5d, 0xde, 0xc6,
0x70, 0x57, 0xbc, 0x58, 0x58, 0x58, 0xd8, 0xd8, 0x58, 0xd5, 0xcb, 0x8c,
0xea, 0xe0, 0xc3, 0x87, 0x1f, 0x83, 0xc1, 0x60, 0x1c, 0x67, 0xb2, 0xaa,
0x06, 0x83, 0xc1, 0x60, 0x30, 0x18, 0xcc, 0xa1, 0xce, 0x88, 0x54, 0x94,
0x46, 0xe1, 0xb0, 0xd0, 0x4e, 0xb2, 0xf7, 0x04, 0x00,
}
s.cmd_code_numbits_ = 448
} }
s.is_initialized_ = true s.is_initialized_ = true