Lines Matching refs:wr

292 static inline size_t INIT get_pos(struct writer *wr)  in get_pos()  argument
295 wr->global_pos + wr->buffer_pos; in get_pos()
298 static inline uint8_t INIT peek_old_byte(struct writer *wr, in peek_old_byte() argument
301 if (!wr->flush) { in peek_old_byte()
303 while (offs > wr->header->dict_size) in peek_old_byte()
304 offs -= wr->header->dict_size; in peek_old_byte()
305 pos = wr->buffer_pos - offs; in peek_old_byte()
306 return wr->buffer[pos]; in peek_old_byte()
308 uint32_t pos = wr->buffer_pos - offs; in peek_old_byte()
309 while (pos >= wr->header->dict_size) in peek_old_byte()
310 pos += wr->header->dict_size; in peek_old_byte()
311 return wr->buffer[pos]; in peek_old_byte()
316 static inline int INIT write_byte(struct writer *wr, uint8_t byte) in write_byte() argument
318 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte; in write_byte()
319 if (wr->flush && wr->buffer_pos == wr->header->dict_size) { in write_byte()
320 wr->buffer_pos = 0; in write_byte()
321 wr->global_pos += wr->header->dict_size; in write_byte()
322 if (wr->flush((char *)wr->buffer, wr->header->dict_size) in write_byte()
323 != wr->header->dict_size) in write_byte()
330 static inline int INIT copy_byte(struct writer *wr, uint32_t offs) in copy_byte() argument
332 return write_byte(wr, peek_old_byte(wr, offs)); in copy_byte()
335 static inline int INIT copy_bytes(struct writer *wr, in copy_bytes() argument
339 if (copy_byte(wr, rep0)) in copy_bytes()
342 } while (len != 0 && wr->buffer_pos < wr->header->dst_size); in copy_bytes()
347 static inline int INIT process_bit0(struct writer *wr, struct rc *rc, in process_bit0() argument
355 * (((get_pos(wr) & literal_pos_mask) << lc) in process_bit0()
356 + (wr->previous_byte >> (8 - lc)))) in process_bit0()
360 int match_byte = peek_old_byte(wr, cst->rep0); in process_bit0()
388 return write_byte(wr, mi); in process_bit0()
391 static inline int INIT process_bit1(struct writer *wr, struct rc *rc, in process_bit1() argument
422 return copy_byte(wr, cst->rep0); in process_bit1()
525 if (cst->rep0 > wr->header->dict_size in process_bit1()
526 || cst->rep0 > get_pos(wr)) in process_bit1()
532 return copy_bytes(wr, cst->rep0, len); in process_bit1()
553 struct writer wr; in unlzma() local
572 wr.header = &header; in unlzma()
573 wr.flush = flush; in unlzma()
574 wr.global_pos = 0; in unlzma()
575 wr.previous_byte = 0; in unlzma()
576 wr.buffer_pos = 0; in unlzma()
613 wr.buffer = output; in unlzma()
615 wr.bufsize = MIN(header.dst_size, header.dict_size); in unlzma()
616 wr.buffer = large_malloc(wr.bufsize); in unlzma()
618 if (wr.buffer == NULL) in unlzma()
631 while (get_pos(&wr) < header.dst_size) { in unlzma()
632 int pos_state = get_pos(&wr) & pos_state_mask; in unlzma()
636 if (process_bit0(&wr, &rc, &cst, p, pos_state, prob, in unlzma()
642 if (process_bit1(&wr, &rc, &cst, p, pos_state, prob)) { in unlzma()
655 if (!wr.flush || wr.flush(wr.buffer, wr.buffer_pos) == wr.buffer_pos) in unlzma()
661 large_free(wr.buffer); in unlzma()