mirror of
https://github.com/golang/go
synced 2024-11-24 19:50:18 -07:00
cmd/link: stop generating garbage in elfhash
All callers already had strings. No need to generate byte slice copies to work on bytes. Performance not measured, but probably helps at least a bit. Change-Id: Iec3230b69724fac68caae7aad46f2ce1504e82e5 Reviewed-on: https://go-review.googlesource.com/20136 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
03f3bfc460
commit
d7cdf66978
@ -1042,19 +1042,15 @@ func elfwritehdr() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Taken directly from the definition document for ELF64 */
|
/* Taken directly from the definition document for ELF64 */
|
||||||
func elfhash(name []byte) uint32 {
|
func elfhash(name string) uint32 {
|
||||||
var h uint32 = 0
|
var h uint32
|
||||||
var g uint32
|
for i := 0; i < len(name); i++ {
|
||||||
for len(name) != 0 {
|
h = (h << 4) + uint32(name[i])
|
||||||
h = (h << 4) + uint32(name[0])
|
if g := h & 0xf0000000; g != 0 {
|
||||||
name = name[1:]
|
|
||||||
g = h & 0xf0000000
|
|
||||||
if g != 0 {
|
|
||||||
h ^= g >> 24
|
h ^= g >> 24
|
||||||
}
|
}
|
||||||
h &= 0x0fffffff
|
h &= 0x0fffffff
|
||||||
}
|
}
|
||||||
|
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1371,7 +1367,7 @@ func elfdynhash() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := sy.Extname
|
name := sy.Extname
|
||||||
hc := elfhash([]byte(name))
|
hc := elfhash(name)
|
||||||
|
|
||||||
b = int(hc % uint32(nbucket))
|
b = int(hc % uint32(nbucket))
|
||||||
chain[sy.Dynid] = buckets[b]
|
chain[sy.Dynid] = buckets[b]
|
||||||
@ -1418,7 +1414,7 @@ func elfdynhash() {
|
|||||||
i++
|
i++
|
||||||
|
|
||||||
// aux struct
|
// aux struct
|
||||||
Adduint32(Ctxt, s, elfhash([]byte(x.vers))) // hash
|
Adduint32(Ctxt, s, elfhash(x.vers)) // hash
|
||||||
Adduint16(Ctxt, s, 0) // flags
|
Adduint16(Ctxt, s, 0) // flags
|
||||||
Adduint16(Ctxt, s, uint16(x.num)) // other - index we refer to this by
|
Adduint16(Ctxt, s, uint16(x.num)) // other - index we refer to this by
|
||||||
Adduint32(Ctxt, s, uint32(Addstring(dynstr, x.vers))) // version string offset
|
Adduint32(Ctxt, s, uint32(Addstring(dynstr, x.vers))) // version string offset
|
||||||
|
Loading…
Reference in New Issue
Block a user