allegro / allegro/bigcache

is it possible to provide an 'unsafe' way to get internal []byte and avoid mem copy?

Aperta
#404 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Go
Stelle
8.2k
Fork
614
Merge medio
5g 12h
PR unite (30g)
1

Descrizione

**What is the issue you are having?**

In some scenarios, the data retrieved from the cache will not be modified and could be directly returned.

**What is BigCache doing that it shouldn't?**
```go
func readEntry(data []byte) []byte {
length := binary.LittleEndian.Uint16(data[timestampSizeInBytes+hashSizeInBytes:])

// copy on read
dst := make([]byte, len(data)-int(headersSizeInBytes+length))
copy(dst, data[headersSizeInBytes+length:])

return dst
}
```
to be --- to recycle the 'dst'
```go
func readEntry(dst, data []byte) []byte {
length := binary.LittleEndian.Uint16(data[timestampSizeInBytes+hashSizeInBytes:])

copy(dst, data[headersSizeInBytes+length:])

return dst
}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.