ObjFW  Diff

Differences From Artifact [da155ca87d]:

  • File src/OFDeflateStream.h — part of check-in [134a1121c7] at 2016-05-29 13:02:05 on branch trunk — Rename OFInflateStream back to OFDeflateStream

    The reason for renaming to OFInflateStream was to have one stream for
    decompression and one for compression in order to reduce memory usage if
    only one of the two is needed, as the ivar layout will be smaller then.
    However, it is more consistent with other stream classes to have one
    stream that can handle both. The increased memory footprint of having
    ivars for compression and decompression can be solved by having a
    pointer to those instead. This will not incur any performance penalty,
    as the pointer will be dereferenced instead of the ivars, meaning the
    overhead is only getting the pointer from the ivars once. (user: js, size: 2902) [annotate] [blame] [check-ins using]

To Artifact [b05d4c196d]:


28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
 */
@interface OFDeflateStream: OFStream
{
#ifdef OF_INFLATE_STREAM_M
@public
#endif
	OFStream *_stream;

	uint8_t _buffer[OF_INFLATE_STREAM_BUFFER_SIZE];
	uint16_t _bufferIndex, _bufferLength;
	uint8_t _byte;
	uint8_t _bitIndex, _savedBitsLength;
	uint16_t _savedBits;
@protected
	uint8_t *_slidingWindow;
	uint16_t _slidingWindowIndex, _slidingWindowMask;
	enum {
		OF_INFLATE_STREAM_BLOCK_HEADER,
		OF_INFLATE_STREAM_UNCOMPRESSED_BLOCK_HEADER,
		OF_INFLATE_STREAM_UNCOMPRESSED_BLOCK,
		OF_INFLATE_STREAM_HUFFMAN_TREE,
		OF_INFLATE_STREAM_HUFFMAN_BLOCK
	} _state;
	union {
		struct {
			uint8_t position;
			uint8_t length[4];
		} uncompressedHeader;
		struct {
			uint16_t position, length;
		} uncompressed;
		struct {
			struct huffman_tree *litLenTree, *distTree;
			struct huffman_tree *codeLenTree, *treeIter;
			uint8_t *lengths;
			uint16_t receivedCount;
			uint8_t value, litLenCodesCount, distCodesCount;
			uint8_t codeLenCodesCount;
		} huffmanTree;
		struct {
			struct huffman_tree *litLenTree, *distTree, *treeIter;
			enum {
				OF_INFLATE_STREAM_WRITE_VALUE,
				OF_INFLATE_STREAM_AWAIT_CODE,
				OF_INFLATE_STREAM_AWAIT_LENGTH_EXTRA_BITS,
				OF_INFLATE_STREAM_AWAIT_DISTANCE,
				OF_INFLATE_STREAM_AWAIT_DISTANCE_EXTRA_BITS,
				OF_INFLATE_STREAM_PROCESS_PAIR
			} state;
			uint16_t value, length, distance;
			uint16_t extraBits;
		} huffman;
	} _context;
	bool _inLastBlock, _atEndOfStream;

}

/*!
 * @brief Creates a new OFDeflateStream with the specified underlying stream.
 *
 * @param stream The underlying stream to which compressed data is written or
 *		 from which compressed data is read







>
|
|
|
|
|
<
|
|
<
<
<
<
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
|
|
|
|
|
|
>







28
29
30
31
32
33
34
35
36
37
38
39
40

41
42






43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62






63
64
65
66
67
68
69
70
71
72
73
74
75
76
 */
@interface OFDeflateStream: OFStream
{
#ifdef OF_INFLATE_STREAM_M
@public
#endif
	OFStream *_stream;
	struct of_deflate_stream_decompression_ivars {
		uint8_t buffer[OF_INFLATE_STREAM_BUFFER_SIZE];
		uint16_t bufferIndex, bufferLength;
		uint8_t byte;
		uint8_t bitIndex, savedBitsLength;
		uint16_t savedBits;

		uint8_t *slidingWindow;
		uint16_t slidingWindowIndex, slidingWindowMask;






		int state;
		union {
			struct {
				uint8_t position;
				uint8_t length[4];
			} uncompressedHeader;
			struct {
				uint16_t position, length;
			} uncompressed;
			struct {
				struct huffman_tree *litLenTree, *distTree;
				struct huffman_tree *codeLenTree, *treeIter;
				uint8_t *lengths;
				uint16_t receivedCount;
				uint8_t value, litLenCodesCount, distCodesCount;
				uint8_t codeLenCodesCount;
			} huffmanTree;
			struct {
				struct huffman_tree *litLenTree, *distTree;
				struct huffman_tree *treeIter;






				int state;
				uint16_t value, length, distance;
				uint16_t extraBits;
			} huffman;
		} context;
		bool inLastBlock, atEndOfStream;
	} *_decompression;
}

/*!
 * @brief Creates a new OFDeflateStream with the specified underlying stream.
 *
 * @param stream The underlying stream to which compressed data is written or
 *		 from which compressed data is read