allegro / allegro/bigcache

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

Open
#404 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
8.2k
Forks
614
Avg merge
5d 12h
Merged PRs (30d)
1

Description

**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
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.