• Eric Myhre's avatar
    Add scratch.Reader tool, helpful for decoders. · 3040f082
    Eric Myhre authored
    The docs in the diff should cover it pretty well.
    It's a reader-wrapper that does a lot of extremely common
    buffering and small-read operations that parsers tend to need.
    
    This emerges from some older generation of code in refmt with similar purpose:
    https://github.com/polydawn/refmt/blob/master/shared/reader.go
    Unlike those antecedents, this one is a single concrete implementation,
    rather than using interfaces to allow switching between the two major modes of use.
    This is surely uglier code, but I think the result is more optimizable.
    
    The tests include aggressive checks that operations take exactly as
    many allocations as planned -- and mostly, that's *zero*.
    
    In the next couple of commits, I'll be adding parsers which use this.
    
    Benchmarks are still forthcoming.  My recollection from the previous
    bout of this in refmt was that microbenchmarking this type wasn't
    a great use of time, because when we start benchmarking codecs built
    *upon* it, and especially, when looking at the pprof reports from that,
    we'll see this reader showing up plain as day there, and nicely
    contextualized... so, we'll just save our efforts for that point.
    3040f082
reader.go 12.4 KB