MCPcopy Create free account
hub / github.com/SheepChef/Abracadabra / matchLine

Function matchLine

src/javascript/unishox2.js:387–456  ·  view source on GitHub ↗
(
  input,
  len,
  l,
  out,
  olen,
  ol,
  prev_lines,
  prev_lines_idx,
  state,
  usx_hcodes,
  usx_hcode_lens
)

Source from the content-addressed store, hash-verified

385}
386
387function matchLine(
388 input,
389 len,
390 l,
391 out,
392 olen,
393 ol,
394 prev_lines,
395 prev_lines_idx,
396 state,
397 usx_hcodes,
398 usx_hcode_lens
399) {
400 var last_ol = ol;
401 var last_len = 0;
402 var last_dist = 0;
403 var last_ctx = 0;
404 var line_ctr = 0;
405 var j = 0;
406 do {
407 var i, k;
408 var prev_line = prev_lines[prev_lines_idx - line_ctr];
409 var line_len = prev_line.length;
410 var limit = line_ctr == 0 ? l : line_len;
411 for (; j < limit; j++) {
412 for (i = l, k = j; k < line_len && k < limit && i < len; k++, i++) {
413 if (prev_line[k] !== input[i]) break;
414 }
415 while (prev_line[k] >> 6 == 2) k--; // Skip partial UTF-8 matches
416 if (k - j >= NICE_LEN) {
417 if (last_len > 0) {
418 if (j > last_dist) continue;
419 //int saving = ((k - j) - last_len) + (last_dist - j) + (last_ctx - line_ctr);
420 //if (saving < 0) {
421 // //printf("No savng: %d\n", saving);
422 // continue;
423 //}
424 ol = last_ol;
425 }
426 last_len = k - j;
427 last_dist = j;
428 last_ctx = line_ctr;
429 ol = append_switch_code(out, olen, ol, state);
430 ol = append_bits(
431 out,
432 olen,
433 ol,
434 usx_hcodes[USX_DICT],
435 usx_hcode_lens[USX_DICT]
436 );
437 ol = encodeCount(out, olen, ol, last_len - NICE_LEN);
438 ol = encodeCount(out, olen, ol, last_dist);
439 ol = encodeCount(out, olen, ol, last_ctx);
440 /*
441 if ((*ol - last_ol) > (last_len * 4)) {
442 last_len = 0;
443 *ol = last_ol;
444 }*/

Callers 1

unishox2_compressFunction · 0.85

Calls 3

append_switch_codeFunction · 0.85
append_bitsFunction · 0.85
encodeCountFunction · 0.85

Tested by

no test coverage detected