1 /* Copyright 2015 Google Inc. All Rights Reserved.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
21 #if defined(__cplusplus) || defined(c_plusplus)
25 void BrotliStateInit(BrotliState
* s
) {
28 s
->state
= BROTLI_STATE_UNINITED
;
29 s
->sub_state
[0] = BROTLI_STATE_SUB_NONE
;
30 s
->sub_state
[1] = BROTLI_STATE_SUB_NONE
;
32 s
->block_type_trees
= NULL
;
33 s
->block_len_trees
= NULL
;
36 s
->context_map
= NULL
;
37 s
->context_modes
= NULL
;
38 s
->dist_context_map
= NULL
;
39 s
->context_map_slice
= NULL
;
40 s
->dist_context_map_slice
= NULL
;
42 for (i
= 0; i
< 3; ++i
) {
43 s
->hgroup
[i
].codes
= NULL
;
44 s
->hgroup
[i
].htrees
= NULL
;
47 s
->code_lengths
= NULL
;
48 s
->context_map_table
= NULL
;
51 void BrotliStateCleanup(BrotliState
* s
) {
54 if (s
->context_map_table
!= 0) {
55 free(s
->context_map_table
);
57 if (s
->code_lengths
!= 0) {
58 free(s
->code_lengths
);
61 if (s
->context_modes
!= 0) {
62 free(s
->context_modes
);
64 if (s
->context_map
!= 0) {
67 if (s
->dist_context_map
!= 0) {
68 free(s
->dist_context_map
);
70 for (i
= 0; i
< 3; ++i
) {
71 BrotliHuffmanTreeGroupRelease(&s
->hgroup
[i
]);
74 if (s
->ringbuffer
!= 0) {
77 if (s
->block_type_trees
!= 0) {
78 free(s
->block_type_trees
);
80 if (s
->block_len_trees
!= 0) {
81 free(s
->block_len_trees
);
85 #if defined(__cplusplus) || defined(c_plusplus)