Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

writeMatch

Private Function
std.compress.flate.Decompress.writeMatch
fn writeMatch(w: *Writer, length: u16, distance: u16) !void

Write match (back-reference to the same data slice) starting at distance back from current write position, and length of bytes. length may be less than the minimum match length to allow for writing partial matches, but must be greater than zero.

Params

  • w: *Writer
  • length: u16
  • distance: u16

File

compress/flate/Decompress.zig:523
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
fn writeMatch(w: *Writer, length: u16, distance: u16) !void {
    if (w.end < distance) return error.InvalidMatch;
    assert(length > 0);
    assert(length <= token.max_length);
    assert(distance >= token.min_distance);
    assert(distance <= token.max_distance);

    // This is not a @memmove; it intentionally repeats patterns caused by
    // iterating one byte at a time.
    const dest = try w.writableSlicePreserve(flate.history_len, length);
    const end = dest.ptr - w.buffer.ptr;
    const src = w.buffer[end - distance ..][0..length];
    if (distance >= length) {
        @memcpy(dest, src);
    } else if (distance == 1) {
        // Repeating copy of single byte
        @memset(dest, src[0]);
    } else {
        // Repeating copy of multiple bytes
        for (dest, src) |*d, s| d.* = s;
    }
}