(dst *tokens, src []byte)
| 320 | } |
| 321 | |
| 322 | func (e *fastEncL5Window) Encode(dst *tokens, src []byte) { |
| 323 | const ( |
| 324 | inputMargin = 12 - 1 |
| 325 | minNonLiteralBlockSize = 1 + 1 + inputMargin |
| 326 | hashShortBytes = 4 |
| 327 | ) |
| 328 | maxMatchOffset := e.maxOffset |
| 329 | if debugDeflate && e.cur < 0 { |
| 330 | panic(fmt.Sprint("e.cur < 0: ", e.cur)) |
| 331 | } |
| 332 | |
| 333 | // Protect against e.cur wraparound. |
| 334 | for e.cur >= bufferReset { |
| 335 | if len(e.hist) == 0 { |
| 336 | for i := range e.table[:] { |
| 337 | e.table[i] = tableEntry{} |
| 338 | } |
| 339 | for i := range e.bTable[:] { |
| 340 | e.bTable[i] = tableEntryPrev{} |
| 341 | } |
| 342 | e.cur = maxMatchOffset |
| 343 | break |
| 344 | } |
| 345 | // Shift down everything in the table that isn't already too far away. |
| 346 | minOff := e.cur + int32(len(e.hist)) - maxMatchOffset |
| 347 | for i := range e.table[:] { |
| 348 | v := e.table[i].offset |
| 349 | if v <= minOff { |
| 350 | v = 0 |
| 351 | } else { |
| 352 | v = v - e.cur + maxMatchOffset |
| 353 | } |
| 354 | e.table[i].offset = v |
| 355 | } |
| 356 | for i := range e.bTable[:] { |
| 357 | v := e.bTable[i] |
| 358 | if v.Cur.offset <= minOff { |
| 359 | v.Cur.offset = 0 |
| 360 | v.Prev.offset = 0 |
| 361 | } else { |
| 362 | v.Cur.offset = v.Cur.offset - e.cur + maxMatchOffset |
| 363 | if v.Prev.offset <= minOff { |
| 364 | v.Prev.offset = 0 |
| 365 | } else { |
| 366 | v.Prev.offset = v.Prev.offset - e.cur + maxMatchOffset |
| 367 | } |
| 368 | } |
| 369 | e.bTable[i] = v |
| 370 | } |
| 371 | e.cur = maxMatchOffset |
| 372 | } |
| 373 | |
| 374 | s := e.addBlock(src) |
| 375 | |
| 376 | // This check isn't in the Snappy implementation, but there, the caller |
| 377 | // instead of the callee handles this case. |
| 378 | if len(src) < minNonLiteralBlockSize { |
| 379 | // We do not fill the token table. |
nothing calls this directly
no test coverage detected