MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / _deflateSlow

Method _deflateSlow

packages/alphatab/src/zip/DeflaterEngine.ts:198–283  ·  view source on GitHub ↗
(flush: boolean, finish: boolean)

Source from the content-addressed store, hash-verified

196 }
197
198 private _deflateSlow(flush: boolean, finish: boolean): boolean {
199 if (this._lookahead < DeflaterConstants.minLookahead && !flush) {
200 return false;
201 }
202
203 while (this._lookahead >= DeflaterConstants.minLookahead || flush) {
204 if (this._lookahead === 0) {
205 if (this._prevAvailable) {
206 this._huffman.tallyLit(this._window[this._strstart - 1] & 0xff);
207 }
208 this._prevAvailable = false;
209
210 // We are flushing everything
211 this._huffman.flushBlock(this._window, this._blockStart, this._strstart - this._blockStart, finish);
212 this._blockStart = this._strstart;
213 return false;
214 }
215
216 if (this._strstart >= 2 * DeflaterConstants.wsize - DeflaterConstants.minLookahead) {
217 /* slide window, as FindLongestMatch needs this.
218 * This should only happen when flushing and the window
219 * is almost full.
220 */
221 this._slideWindow();
222 }
223
224 const prevMatch = this._matchStart;
225 let prevLen = this._matchLen;
226 if (this._lookahead >= DeflaterConstants.minMatch) {
227 const hashHead = this._insertString();
228
229 if (
230 hashHead !== 0 &&
231 this._strstart - hashHead <= DeflaterConstants.maxDist &&
232 this._findLongestMatch(hashHead)
233 ) {
234 // longestMatch sets matchStart and matchLen
235
236 // Discard match if too small and too far away
237 if (
238 this._matchLen === DeflaterConstants.minMatch &&
239 this._strstart - this._matchStart > DeflaterEngine._tooFar
240 ) {
241 this._matchLen = DeflaterConstants.minMatch - 1;
242 }
243 }
244 }
245
246 // previous match was better
247 if (prevLen >= DeflaterConstants.minMatch && this._matchLen <= prevLen) {
248 this._huffman.tallyDist(this._strstart - 1 - prevMatch, prevLen);
249 prevLen -= 2;
250 do {
251 this._strstart++;
252 this._lookahead--;
253 if (this._lookahead >= DeflaterConstants.minMatch) {
254 this._insertString();
255 }

Callers 1

deflateMethod · 0.95

Calls 7

_slideWindowMethod · 0.95
_insertStringMethod · 0.95
_findLongestMatchMethod · 0.95
tallyLitMethod · 0.80
flushBlockMethod · 0.80
tallyDistMethod · 0.80
isFullMethod · 0.80

Tested by

no test coverage detected