bool DeflateFast(bool flush, bool finish) { if (lookahead < MIN_LOOKAHEAD && !flush) { return(false); } while (lookahead >= MIN_LOOKAHEAD || flush) { if (lookahead == 0) { // We are flushing everything huffman.FlushBlock(window, blockStart, strstart - blockStart, finish); blockStart = strstart; return(false); } if (strstart > 2 * WSIZE - MIN_LOOKAHEAD) { /* slide window, as FindLongestMatch needs this. * This should only happen when flushing and the window * is almost full. */ SlideWindow(); } int hashHead; if (lookahead >= MIN_MATCH && (hashHead = InsertString()) != 0 && strategy != DeflateStrategy.HuffmanOnly && strstart - hashHead <= MAX_DIST && FindLongestMatch(hashHead)) { // longestMatch sets matchStart and matchLen #if DebugDeflation if (DeflaterConstants.DEBUGGING) { for (int i = 0; i < matchLen; i++) { if (window[strstart + i] != window[matchStart + i]) { throw new SharpZipBaseException("Match failure"); } } } #endif bool full = huffman.TallyDist(strstart - matchStart, matchLen); lookahead -= matchLen; if (matchLen <= max_lazy && lookahead >= MIN_MATCH) { while (--matchLen > 0) { ++strstart; InsertString(); } ++strstart; } else { strstart += matchLen; if (lookahead >= MIN_MATCH - 1) { UpdateHash(); } } matchLen = MIN_MATCH - 1; if (!full) { continue; } } else { // No match found huffman.TallyLit(window[strstart] & 0xff); ++strstart; --lookahead; } if (huffman.IsFull()) { bool lastBlock = finish && (lookahead == 0); huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock); blockStart = strstart; return(!lastBlock); } } return(true); }
private bool DeflateFast(bool flush, bool finish) { if (lookahead < 262 && !flush) { return(false); } while (lookahead >= 262 || flush) { if (lookahead == 0) { huffman.FlushBlock(window, blockStart, strstart - blockStart, finish); blockStart = strstart; return(false); } if (strstart > 65274) { SlideWindow(); } int num; if (lookahead >= 3 && (num = InsertString()) != 0 && strategy != DeflateStrategy.HuffmanOnly && strstart - num <= 32506 && FindLongestMatch(num)) { bool flag = huffman.TallyDist(strstart - matchStart, matchLen); lookahead -= matchLen; if (matchLen <= max_lazy && lookahead >= 3) { while (--matchLen > 0) { strstart++; InsertString(); } strstart++; } else { strstart += matchLen; if (lookahead >= 2) { UpdateHash(); } } matchLen = 2; if (!flag) { continue; } } else { huffman.TallyLit(window[strstart] & 0xFF); strstart++; lookahead--; } if (huffman.IsFull()) { bool flag2 = finish && lookahead == 0; huffman.FlushBlock(window, blockStart, strstart - blockStart, flag2); blockStart = strstart; return(!flag2); } } return(true); }
private bool DeflateFast(bool flush, bool finish) { if (lookahead < MIN_LOOKAHEAD && !flush) { return(false); } while (lookahead >= MIN_LOOKAHEAD || flush) { if (lookahead == 0) { /* We are flushing everything */ huffman.FlushBlock(window, blockStart, strstart - blockStart, finish); blockStart = strstart; return(false); } if (strstart > 2 * WSIZE - MIN_LOOKAHEAD) { /* slide window, as findLongestMatch need this. * This should only happen when flushing and the window * is almost full. */ SlideWindow(); } int hashHead; if (lookahead >= MIN_MATCH && (hashHead = InsertString()) != 0 && strategy != DeflateStrategy.HuffmanOnly && strstart - hashHead <= MAX_DIST && FindLongestMatch(hashHead)) { /* longestMatch sets matchStart and matchLen */ // if (DeflaterConstants.DEBUGGING) { // for (int i = 0 ; i < matchLen; i++) { // if (window[strstart+i] != window[matchStart + i]) { // throw new Exception(); // } // } // } // -jr- Hak hak hak this stops problems with fast/low compression and index out of range if (huffman.TallyDist(strstart - matchStart, matchLen)) { bool lastBlock = finish && lookahead == 0; huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock); blockStart = strstart; } lookahead -= matchLen; if (matchLen <= max_lazy && lookahead >= MIN_MATCH) { while (--matchLen > 0) { ++strstart; InsertString(); } ++strstart; } else { strstart += matchLen; if (lookahead >= MIN_MATCH - 1) { UpdateHash(); } } matchLen = MIN_MATCH - 1; continue; } else { /* No match found */ huffman.TallyLit(window[strstart] & 0xff); ++strstart; --lookahead; } if (huffman.IsFull()) { bool lastBlock = finish && lookahead == 0; huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock); blockStart = strstart; return(!lastBlock); } } return(true); }