Created
September 21, 2022 06:38
-
-
Save DennisPing/e24019d2e2d5c357fabc7034e5e7102b to your computer and use it in GitHub Desktop.
Compiler magic?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func AppendDataNaive(packet1 []byte, packet2 []byte) uint16 { | |
// Do some initial work done with packet1 and packet2... | |
// Don't set any capacity, let Go auto-resize | |
data := make([]byte, 0) | |
data = append(data, packet1...) | |
data = append(data, packet2...) | |
// Do some calculations with 'data' | |
return calculatedValue | |
} | |
func AppendDataSmart(packet1 []byte, packet2 []byte) uint16 { | |
// Do some initial work done with packet1 and packet2... | |
// Make a slice with len = 0 but underlying capacity of len1 + len2 | |
data := make([]byte, 0, len(packet1)+len(packet2)) | |
data = append(data, packet1...) | |
data = append(data, packet2...) | |
// Do some calculations with 'data' | |
return calculatedValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment