• Dmitry Vyukov's avatar
    cmd/gc: don't copy []byte during string concatenation · 205ae07c
    Dmitry Vyukov authored
    Consider the following code:
    
    s := "(" + string(byteSlice) + ")"
    
    Currently we allocate a new string during []byte->string conversion,
    and pass it to concatstrings. String allocation is unnecessary in
    this case, because concatstrings does memorize the strings for later use.
    This change uses slicebytetostringtmp to construct temp string directly
    from []byte buffer and passes it to concatstrings.
    
    I've found few such cases in std lib:
    
    	s += string(msg[off:off+c]) + "."
    	buf.WriteString("Sec-WebSocket-Accept: " + string(c.accept) + "\r\n")
    	bw.WriteString("Sec-WebSocket-Key: " + string(nonce) + "\r\n")
    	err = xml.Unmarshal([]byte("<Top>"+string(data)+"</Top>"), &logStruct)
    	d.err = d.syntaxError("invalid XML name: " + string(b))
    	return m, ProtocolError("malformed MIME header line: " + string(kv))
    
    But there are much more in our internal code base.
    
    Change-Id: I42f401f317131237ddd0cb9786b0940213af16fb
    Reviewed-on: https://go-review.googlesource.com/3163Reviewed-by: 's avatarKeith Randall <khr@golang.org>
    Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    205ae07c
Name
Last commit
Last update
api Loading commit data...
doc Loading commit data...
include Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...