// Make sure this is cleared in case compression level is switched later. // TODO: It's possible we don't need this or could do this elsewhere later // but just do this here to avoid causing issues for now.
d.params.saved_match_len = 0; letmut bytes_written = d.lz.total_bytes; letmut src_pos = d.params.src_pos; letmut lookahead_size = d.dict.lookahead_size; letmut lookahead_pos = d.dict.lookahead_pos;
while src_pos < in_buf.len() || (d.params.flush != TDEFLFlush::None && lookahead_size != 0) { let src_buf_left = in_buf.len() - src_pos; let num_bytes_to_process = cmp::min(src_buf_left, MAX_MATCH_LEN - lookahead_size);
if lookahead_size + d.dict.size >= usize::from(MIN_MATCH_LEN) - 1
&& num_bytes_to_process > 0
{ let dictb = &mut d.dict.b;
letmut dst_pos = (lookahead_pos + lookahead_size) & LZ_DICT_SIZE_MASK; letmut ins_pos = lookahead_pos + lookahead_size - 2; // Start the hash value from the first two bytes letmut hash = update_hash(
u16::from(dictb.dict[ins_pos & LZ_DICT_SIZE_MASK]),
dictb.dict[(ins_pos + 1) & LZ_DICT_SIZE_MASK],
);
lookahead_size += num_bytes_to_process;
for &c in &in_buf[src_pos..src_pos + num_bytes_to_process] { // Add byte to input buffer.
dictb.dict[dst_pos] = c; if dst_pos < MAX_MATCH_LEN - 1 {
dictb.dict[LZ_DICT_SIZE + dst_pos] = c;
}
// Generate hash from the current byte,
hash = update_hash(hash, c);
dictb.next[ins_pos & LZ_DICT_SIZE_MASK] = dictb.hash[hash as usize]; // and insert it into the hash chain.
dictb.hash[hash as usize] = ins_pos as u16;
dst_pos = (dst_pos + 1) & LZ_DICT_SIZE_MASK;
ins_pos += 1;
}
src_pos += num_bytes_to_process;
} else { let dictb = &mut d.dict.b; for &c in &in_buf[src_pos..src_pos + num_bytes_to_process] { let dst_pos = (lookahead_pos + lookahead_size) & LZ_DICT_SIZE_MASK;
dictb.dict[dst_pos] = c; if dst_pos < MAX_MATCH_LEN - 1 {
dictb.dict[LZ_DICT_SIZE + dst_pos] = c;
}
if bytes_written > 31 * 1024 {
d.lz.total_bytes = bytes_written;
d.params.src_pos = src_pos; // These values are used in flush_block, so we need to write them back here.
d.dict.lookahead_size = lookahead_size;
d.dict.lookahead_pos = lookahead_pos;
let n = flush_block(d, callback, TDEFLFlush::None)
.unwrap_or(TDEFLStatus::PutBufFailed as i32); if n != 0 { return n > 0;
}
bytes_written = d.lz.total_bytes;
}
}
letmutdst_pos=(lookahead_pos+lookahead_size)&LZ_DICT_SIZE_MASK; letmutins_pos=lookahead_pos+lookahead_size-2; // Start the hash value from the first two bytes letmuthash=update_hash( u16::from(dictb.dict[ins_pos&LZ_DICT_SIZE_MASK]), dictb.dict[(ins_pos+1)&LZ_DICT_SIZE_MASK], );
// Generate hash from the current byte, hash=update_hash(hash,c); dictb.next[ins_pos&LZ_DICT_SIZE_MASK]=dictb.hash[hashasusize]; // and insert it into the hash chain. dictb.hash[hashasusize]=ins_posasu16; dst_pos=(dst_pos+1)&LZ_DICT_SIZE_MASK; ins_pos+=1; } src_pos+=num_bytes_to_process; }else{ letdictb=&mutd.dict.b; for&cin&in_buf[src_pos..src_pos+num_bytes_to_process]{ letdst_pos=(lookahead_pos+lookahead_size)&LZ_DICT_SIZE_MASK; dictb.dict[dst_pos]=c; ifdst_pos<MAX_MATCH_LEN-1{ dictb.dict[LZ_DICT_SIZE+dst_pos]=c; }
letmutlen_to_move=1; letmutcur_match_dist=0; letmutcur_match_len=ifsaved_match_len!=0{ saved_match_len }else{ u32::from(MIN_MATCH_LEN)-1 }; letcur_pos=lookahead_pos&LZ_DICT_SIZE_MASK; // If TDEFL_RLE_MATCHES is set, we only look for repeating sequences of the current byte. ifd.dict.size!=0&&d.params.flags&TDEFL_FORCE_ALL_RAW_BLOCKS==0{ letc=d.dict.b.dict[(cur_pos.wrapping_sub(1))&LZ_DICT_SIZE_MASK]; cur_match_len=d.dict.b.dict[cur_pos..(cur_pos+lookahead_size)] .iter() .take_while(|&x|*x==c) .count()asu32; ifcur_match_len<MIN_MATCH_LEN.into(){ cur_match_len=0 }else{ cur_match_dist=1 } }
ifsaved_match_len!=0{ ifcur_match_len>saved_match_len{ record_literal(&mutd.huff,&mutd.lz,saved_lit); ifcur_match_len>=128{ record_match(&mutd.huff,&mutd.lz,cur_match_len,cur_match_dist); saved_match_len=0; len_to_move=cur_match_lenasusize; }else{ saved_lit=d.dict.b.dict[cur_pos]; saved_match_dist=cur_match_dist; saved_match_len=cur_match_len; } }else{ record_match(&mutd.huff,&mutd.lz,saved_match_len,saved_match_dist); len_to_move=(saved_match_len-1)asusize; saved_match_len=0; } }elseifcur_match_dist==0{ record_literal( &mutd.huff, &mutd.lz, d.dict.b.dict[cmp::min(cur_pos,d.dict.b.dict.len()-1)], ); }elseifd.params.greedy_parsing ||(d.params.flags&TDEFL_RLE_MATCHES!=0) ||cur_match_len>=128 { // If we are using lazy matching, check for matches at the next byte if the current // match was shorter than 128 bytes. record_match(&mutd.huff,&mutd.lz,cur_match_len,cur_match_dist); len_to_move=cur_match_lenasusize; }else{ saved_lit=d.dict.b.dict[cmp::min(cur_pos,d.dict.b.dict.len()-1)]; saved_match_dist=cur_match_dist; saved_match_len=cur_match_len; }
iflz_buf_tight||fat_or_raw{ d.params.src_pos=src_pos; // These values are used in flush_block, so we need to write them back here. d.dict.lookahead_size=lookahead_size; d.dict.lookahead_pos=lookahead_pos;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.11Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.