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

internal/conv: fix wrong string to bytes implementation #9141

Merged
merged 1 commit into from
Apr 19, 2021
Merged

internal/conv: fix wrong string to bytes implementation #9141

merged 1 commit into from
Apr 19, 2021

Commits on Apr 19, 2021

  1. internal/conv: fix wrong string to bytes implementation

    UnsafeStrToBytes is currently not safe for -d=checkptr=2, since when it
    cast from smaller struct (string) to bigger struct ([]byte). That causes
    checkptr complains as the casting straddle multiple heap objects.
    
    To fix this, we have to get the string header first, then use its fields
    to construct the slice.
    
    New implementation performs the same speed with the old (wrong) one.
    
    name                old time/op    new time/op    delta
    UnsafeStrToBytes-8    25.7ns ± 1%    25.7ns ± 3%   ~     (p=0.931 n=10+17)
    
    name                old alloc/op   new alloc/op   delta
    UnsafeStrToBytes-8     7.00B ± 0%     7.00B ± 0%   ~     (all equal)
    
    name                old allocs/op  new allocs/op  delta
    UnsafeStrToBytes-8      0.00           0.00        ~     (all equal)
    
    While at it, also simplify UnsafeBytesToStr implementation, since when
    we can pass the slice directly to unsafe.Pointer, instead of getting the
    slice header first.
    Cuong Manh Le authored and cuonglm committed Apr 19, 2021
    Configuration menu
    Copy the full SHA
    c2113b9 View commit details
    Browse the repository at this point in the history