static block_state deflate_rle (deflate_state *s, int flush);
static block_state deflate_huff (deflate_state *s, int flush);
static void lm_init (deflate_state *s);
-static void putShortMSB (deflate_state *s, uint16_t b);
ZLIB_INTERNAL unsigned read_buf (PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
extern void crc_reset(deflate_state *const s);
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13 - 6 + wraplen;
}
-/* =========================================================================
- * Put a short in the pending buffer. The 16-bit value is put in MSB order.
- * IN assertion: the stream state is correct and there is enough room in
- * pending_buf.
- */
-static void putShortMSB(deflate_state *s, uint16_t b) {
- put_byte(s, (unsigned char)(b >> 8));
- put_byte(s, (unsigned char)(b & 0xff));
-}
-
/* =========================================================================
* Flush as much pending output as possible. All deflate() output, except for
* some deflate_stored() output, goes through this function so some
if (s->strstart != 0) header |= PRESET_DICT;
header += 31 - (header % 31);
- putShortMSB(s, header);
+ put_short_msb(s, header);
/* Save the adler32 of the preset dictionary: */
if (s->strstart != 0) {
- putShortMSB(s, (uint16_t)(strm->adler >> 16));
- putShortMSB(s, (uint16_t)(strm->adler));
+ put_uint32_msb(s, strm->adler);
}
strm->adler = functable.adler32(0L, NULL, 0);
s->status = BUSY_STATE;
put_byte(s, 139);
put_byte(s, 8);
if (s->gzhead == NULL) {
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
+ put_uint32(s, 0);
put_byte(s, 0);
put_byte(s, s->level == 9 ? 2 :
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 4 : 0));
(s->gzhead->name == NULL ? 0 : 8) +
(s->gzhead->comment == NULL ? 0 : 16)
);
- put_byte(s, (unsigned char)(s->gzhead->time & 0xff));
- put_byte(s, (unsigned char)((s->gzhead->time >> 8) & 0xff));
- put_byte(s, (unsigned char)((s->gzhead->time >> 16) & 0xff));
- put_byte(s, (unsigned char)((s->gzhead->time >> 24) & 0xff));
+ put_uint32(s, s->gzhead->time);
put_byte(s, s->level == 9 ? 2 :
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 4 : 0));
put_byte(s, s->gzhead->os & 0xff);
if (s->gzhead->extra != NULL) {
- put_byte(s, s->gzhead->extra_len & 0xff);
- put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
+ put_short(s, s->gzhead->extra_len);
}
if (s->gzhead->hcrc)
strm->adler = PREFIX(crc32)(strm->adler, s->pending_buf, s->pending);
if (s->status == NAME_STATE) {
if (s->gzhead->name != NULL) {
uint32_t beg = s->pending; /* start of bytes to update crc */
- int val;
+ unsigned char val;
do {
if (s->pending == s->pending_buf_size) {
if (s->status == COMMENT_STATE) {
if (s->gzhead->comment != NULL) {
uint32_t beg = s->pending; /* start of bytes to update crc */
- int val;
+ unsigned char val;
do {
if (s->pending == s->pending_buf_size) {
return Z_OK;
}
}
- put_byte(s, (unsigned char)(strm->adler & 0xff));
- put_byte(s, (unsigned char)((strm->adler >> 8) & 0xff));
+ put_short(s, (uint16_t)strm->adler);
crc_reset(s);
}
s->status = BUSY_STATE;
# ifdef X86_PCLMULQDQ_CRC
crc_finalize(s);
# endif
- put_byte(s, (unsigned char)(strm->adler & 0xff));
- put_byte(s, (unsigned char)((strm->adler >> 8) & 0xff));
- put_byte(s, (unsigned char)((strm->adler >> 16) & 0xff));
- put_byte(s, (unsigned char)((strm->adler >> 24) & 0xff));
- put_byte(s, (unsigned char)(strm->total_in & 0xff));
- put_byte(s, (unsigned char)((strm->total_in >> 8) & 0xff));
- put_byte(s, (unsigned char)((strm->total_in >> 16) & 0xff));
- put_byte(s, (unsigned char)((strm->total_in >> 24) & 0xff));
+ put_uint32(s, strm->adler);
+ put_uint32(s, strm->total_in);
} else
#endif
{
- putShortMSB(s, (uint16_t)(strm->adler >> 16));
- putShortMSB(s, (uint16_t)strm->adler);
+ put_uint32_msb(s, strm->adler);
}
flush_pending(strm);
/* If avail_out is zero, the application will call deflate again
/* ===========================================================================
* Output a short LSB first on the stream.
- * IN assertion: there is enough room in pendingBuf.
+ * IN assertion: there is enough room in pending_buf.
*/
static inline void put_short(deflate_state *s, uint16_t w) {
-#if BYTE_ORDER == BIG_ENDIAN
- w = ZSWAP16(w);
-#endif
- memcpy(&(s->pending_buf[s->pending]), &w, sizeof(uint16_t));
+#if defined(UNALIGNED_OK)
+ *(uint16_t *)(&s->pending_buf[s->pending]) = w;
s->pending += 2;
+#else
+ put_byte(s, (w & 0xff));
+ put_byte(s, ((w >> 8) & 0xff));
+#endif
+}
+
+/* ===========================================================================
+ * Output a short MSB first on the stream.
+ * IN assertion: there is enough room in pending_buf.
+ */
+static inline void put_short_msb(deflate_state *s, uint16_t w) {
+ put_byte(s, ((w >> 8) & 0xff));
+ put_byte(s, (w & 0xff));
+}
+
+/* ===========================================================================
+ * Output a 32-bit unsigned int LSB first on the stream.
+ * IN assertion: there is enough room in pending_buf.
+ */
+static inline void put_uint32(deflate_state *s, uint32_t dw) {
+#if defined(UNALIGNED_OK)
+ *(uint32_t *)(&s->pending_buf[s->pending]) = dw;
+ s->pending += 4;
+#else
+ put_byte(s, (dw & 0xff));
+ put_byte(s, ((dw >> 8) & 0xff));
+ put_byte(s, ((dw >> 16) & 0xff));
+ put_byte(s, ((dw >> 24) & 0xff));
+#endif
+}
+
+/* ===========================================================================
+ * Output a 32-bit unsigned int MSB first on the stream.
+ * IN assertion: there is enough room in pending_buf.
+ */
+static inline void put_uint32_msb(deflate_state *s, uint32_t dw) {
+#if defined(UNALIGNED_OK)
+ *(uint32_t *)(&s->pending_buf[s->pending]) = ZSWAP32(dw);
+ s->pending += 4;
+#else
+ put_byte(s, ((dw >> 24) & 0xff));
+ put_byte(s, ((dw >> 16) & 0xff));
+ put_byte(s, ((dw >> 8) & 0xff));
+ put_byte(s, (dw & 0xff));
+#endif
}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)