Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Image.SubImageInto method #2903

Closed

Commits on Feb 4, 2024

  1. add Image.SubImageInto method

    Instead of allocating the result on heap for the user,
    allow the caller side to decide whether it should be heap-allocated
    or stack-allocated.
    
    This new method allows us to have a zero-alloc SubImage routine
    for the use cases where we don't want to make an extra allocation.
    
    The performance difference is measurable (comparison is done with benchstat):
    
    	name             old time/op    new time/op    delta
    	SubImage-12     203ns ± 2%      33ns ± 2%   -83.91%  (p=0.000 n=20+19)
    
    	name             old alloc/op   new alloc/op   delta
    	SubImage-12      112B ± 0%        0B       -100.00%  (p=0.000 n=20+20)
    
    Using SubImage is `~203ns`, SubImageInto is `~33ns`.
    SubImage does 1 allocation, SubImageInto does none.
    
    SubImage is rewritten in a way to avoid the code duplication.
    It should work identically to the previous contract (it returns nil
    if `i` is disposed, etc.)
    
    Fixes hajimehoshi#2902
    quasilyte committed Feb 4, 2024
    Configuration menu
    Copy the full SHA
    1ea88db View commit details
    Browse the repository at this point in the history