Skip to content

Instantly share code, notes, and snippets.

@scottcagno
Last active October 12, 2016 19:45
Show Gist options
  • Select an option

  • Save scottcagno/89abe20fd1d671109476716d85e214f8 to your computer and use it in GitHub Desktop.

Select an option

Save scottcagno/89abe20fd1d671109476716d85e214f8 to your computer and use it in GitHub Desktop.
Notes
string/[]byte casting:
The []byte(s) is not a cast but a conversion. Some conversions are the
same as a cast, like uint(myIntvar), which just reinterprets the bits
in place. Unfortunately that's not the case of string to byte slice
conversion. Byte slices are mutable, strings (string values to be precise)
are not. The outcome is a necessary copy (mem alloc + content transfer)
of the string being made. So yes, it can be costly in some scenarios. *No
encoding transformation is performed. The string (source) bytes are copied
to the slice (destination) bytes as they are.
key indexes:
integers will ALWAYS outperform string or []byte keys when it comes to
comparison and matching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment