fastcache icon indicating copy to clipboard operation
fastcache copied to clipboard

https://github.com/VictoriaMetrics/fastcache/blob/master/fastcache.go#L392

Open superdolt opened this issue 4 years ago • 1 comments

why doesnt use bytes.Equal() ? so we dont need additional string() comparison

if string(k) == string(chunk[idx:idx+keyLen]) {

superdolt avatar Aug 28 '21 23:08 superdolt

Because bytes.Equal is implemented in the same way - see https://cs.opensource.google/go/go/+/refs/tags/go1.17:src/bytes/bytes.go;l=18 :

func Equal(a, b []byte) bool {
    return string(a) == string(b)
}

Go compiler automatically optimizes such a comparison in the most efficient way.

valyala avatar Aug 29 '21 09:08 valyala