Lines Matching full:wr
294 static inline size_t INIT get_pos(struct writer *wr) in get_pos() argument
297 wr->global_pos + wr->buffer_pos; in get_pos()
300 static inline uint8_t INIT peek_old_byte(struct writer *wr, in peek_old_byte() argument
303 if (!wr->flush) { in peek_old_byte()
305 while (offs > wr->header->dict_size) in peek_old_byte()
306 offs -= wr->header->dict_size; in peek_old_byte()
307 pos = wr->buffer_pos - offs; in peek_old_byte()
308 return wr->buffer[pos]; in peek_old_byte()
310 uint32_t pos = wr->buffer_pos - offs; in peek_old_byte()
311 while (pos >= wr->header->dict_size) in peek_old_byte()
312 pos += wr->header->dict_size; in peek_old_byte()
313 return wr->buffer[pos]; in peek_old_byte()
318 static inline int INIT write_byte(struct writer *wr, uint8_t byte) in write_byte() argument
320 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte; in write_byte()
321 if (wr->flush && wr->buffer_pos == wr->header->dict_size) { in write_byte()
322 wr->buffer_pos = 0; in write_byte()
323 wr->global_pos += wr->header->dict_size; in write_byte()
324 if (wr->flush((char *)wr->buffer, wr->header->dict_size) in write_byte()
325 != wr->header->dict_size) in write_byte()
332 static inline int INIT copy_byte(struct writer *wr, uint32_t offs) in copy_byte() argument
334 return write_byte(wr, peek_old_byte(wr, offs)); in copy_byte()
337 static inline int INIT copy_bytes(struct writer *wr, in copy_bytes() argument
341 if (copy_byte(wr, rep0)) in copy_bytes()
344 } while (len != 0 && wr->buffer_pos < wr->header->dst_size); in copy_bytes()
349 static inline int INIT process_bit0(struct writer *wr, struct rc *rc, in process_bit0() argument
357 * (((get_pos(wr) & literal_pos_mask) << lc) in process_bit0()
358 + (wr->previous_byte >> (8 - lc)))) in process_bit0()
362 int match_byte = peek_old_byte(wr, cst->rep0); in process_bit0()
390 return write_byte(wr, mi); in process_bit0()
393 static inline int INIT process_bit1(struct writer *wr, struct rc *rc, in process_bit1() argument
424 return copy_byte(wr, cst->rep0); in process_bit1()
527 if (cst->rep0 > wr->header->dict_size in process_bit1()
528 || cst->rep0 > get_pos(wr)) in process_bit1()
534 return copy_bytes(wr, cst->rep0, len); in process_bit1()
555 struct writer wr; in unlzma() local
574 wr.header = &header; in unlzma()
575 wr.flush = flush; in unlzma()
576 wr.global_pos = 0; in unlzma()
577 wr.previous_byte = 0; in unlzma()
578 wr.buffer_pos = 0; in unlzma()
615 wr.buffer = output; in unlzma()
617 wr.bufsize = MIN(header.dst_size, header.dict_size); in unlzma()
618 wr.buffer = large_malloc(wr.bufsize); in unlzma()
620 if (wr.buffer == NULL) in unlzma()
633 while (get_pos(&wr) < header.dst_size) { in unlzma()
634 int pos_state = get_pos(&wr) & pos_state_mask; in unlzma()
638 if (process_bit0(&wr, &rc, &cst, p, pos_state, prob, in unlzma()
644 if (process_bit1(&wr, &rc, &cst, p, pos_state, prob)) { in unlzma()
657 if (!wr.flush || wr.flush(wr.buffer, wr.buffer_pos) == wr.buffer_pos) in unlzma()
663 large_free(wr.buffer); in unlzma()