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

encoding/json: fix and optimize marshal for quoted string #34127

Closed
wants to merge 1 commit into from

Commits on Sep 10, 2019

  1. encoding/json: fix and optimize marshal for quoted string

    Since Go 1.2 every string can be marshaled to JSON without error even if it
    contains invalid UTF-8 byte sequences. Therefore there is no need to use
    Marshal again for the only reason of enclosing the string in double quotes.
    Not using Marshal here also removes the error check as there has not been a
    way for Marshal to fail anyway.
    
    name old time/op new time/op delta
    Issue34127-4 360ns ± 3% 200ns ± 3% -44.56% (p=0.008 n=5+5)
    
    name old alloc/op new alloc/op delta
    Issue34127-4 56.0B ± 0% 40.0B ± 0% -28.57% (p=0.008 n=5+5)
    
    name old allocs/op new allocs/op delta
    Issue34127-4 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5)
    
    Fixes golang#34154
    breml committed Sep 10, 2019
    Configuration menu
    Copy the full SHA
    9b0ac1d View commit details
    Browse the repository at this point in the history