• David Crawshaw's avatar
    cmd/compile, runtime: new static name encoding · 24ce64d1
    David Crawshaw authored
    Create a byte encoding designed for static Go names.
    
    It is intended to be a compact representation of a name
    and optional tag data that can be turned into a Go string
    without allocating, and describes whether or not it is
    exported without unicode table.
    
    The encoding is described in reflect/type.go:
    
    // The first byte is a bit field containing:
    //
    //	1<<0 the name is exported
    //	1<<1 tag data follows the name
    //	1<<2 pkgPath *string follow the name and tag
    //
    // The next two bytes are the data length:
    //
    //	 l := uint16(data[1])<<8 | uint16(data[2])
    //
    // Bytes [3:3+l] are the string data.
    //
    // If tag data follows then bytes 3+l and 3+l+1 are the tag length,
    // with the data following.
    //
    // If the import path follows, then ptrSize bytes at the end of
    // the data form a *string. The import path is only set for concrete
    // methods that are defined in a different package than their type.
    
    Shrinks binary sizes:
    
    	cmd/go: 164KB (1.6%)
    	jujud:  1.0MB (1.5%)
    
    For #6853.
    
    Change-Id: I46b6591015b17936a443c9efb5009de8dfe8b609
    Reviewed-on: https://go-review.googlesource.com/20968
    Run-TryBot: David Crawshaw <crawshaw@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    24ce64d1
type.go 5.56 KB