EncodeNoHist will encode a block with no history and no following blocks. Most notable difference is that src will not be copied for history and we do not need to check for max match length.
(blk *blockEnc, src []byte)
| 370 | // Most notable difference is that src will not be copied for history and |
| 371 | // we do not need to check for max match length. |
| 372 | func (e *doubleFastEncoder) EncodeNoHist(blk *blockEnc, src []byte) { |
| 373 | const ( |
| 374 | // Input margin is the number of bytes we read (8) |
| 375 | // and the maximum we will read ahead (2) |
| 376 | inputMargin = 8 + 2 |
| 377 | minNonLiteralBlockSize = 16 |
| 378 | ) |
| 379 | |
| 380 | // Protect against e.cur wraparound. |
| 381 | if e.cur >= e.bufferReset { |
| 382 | for i := range e.table[:] { |
| 383 | e.table[i] = tableEntry{} |
| 384 | } |
| 385 | for i := range e.longTable[:] { |
| 386 | e.longTable[i] = tableEntry{} |
| 387 | } |
| 388 | e.cur = e.maxMatchOff |
| 389 | } |
| 390 | |
| 391 | s := int32(0) |
| 392 | blk.size = len(src) |
| 393 | if len(src) < minNonLiteralBlockSize { |
| 394 | blk.extraLits = len(src) |
| 395 | blk.literals = blk.literals[:len(src)] |
| 396 | copy(blk.literals, src) |
| 397 | return |
| 398 | } |
| 399 | |
| 400 | // Override src |
| 401 | sLimit := int32(len(src)) - inputMargin |
| 402 | // stepSize is the number of bytes to skip on every main loop iteration. |
| 403 | // It should be >= 1. |
| 404 | const stepSize = 1 |
| 405 | |
| 406 | const kSearchStrength = 8 |
| 407 | |
| 408 | // nextEmit is where in src the next emitLiteral should start from. |
| 409 | nextEmit := s |
| 410 | cv := load6432(src, s) |
| 411 | |
| 412 | // Relative offsets |
| 413 | offset1 := int32(blk.recentOffsets[0]) |
| 414 | offset2 := int32(blk.recentOffsets[1]) |
| 415 | |
| 416 | addLiterals := func(s *seq, until int32) { |
| 417 | if until == nextEmit { |
| 418 | return |
| 419 | } |
| 420 | blk.literals = append(blk.literals, src[nextEmit:until]...) |
| 421 | s.litLen = uint32(until - nextEmit) |
| 422 | } |
| 423 | if debugEncoder { |
| 424 | println("recent offsets:", blk.recentOffsets) |
| 425 | } |
| 426 | |
| 427 | encodeLoop: |
| 428 | for { |
| 429 | var t int32 |