util/uniq: use generics instead of reflect (#5491)

This takes 75% less time per operation per some benchmarks on my mac.

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
This commit is contained in:
Andrew Dunham
2022-08-30 17:56:51 -04:00
committed by GitHub
parent 1ac4a26fee
commit e945d87d76
3 changed files with 26 additions and 50 deletions

View File

@@ -2843,7 +2843,7 @@ func (c *Conn) bindSocket(rucPtr **RebindingUDPConn, network string, curPortFate
}
ports = append(ports, 0)
// Remove duplicates. (All duplicates are consecutive.)
uniq.ModifySlice(&ports, func(i, j int) bool { return ports[i] == ports[j] })
uniq.ModifySlice(&ports)
var pconn nettype.PacketConn
for _, port := range ports {