helper_not_unsafe.go 673 B

1234567891011121314151617181920
  1. // +build !unsafe
  2. // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
  3. // Use of this source code is governed by a MIT license found in the LICENSE file.
  4. package codec
  5. // stringView returns a view of the []byte as a string.
  6. // In unsafe mode, it doesn't incur allocation and copying caused by conversion.
  7. // In regular safe mode, it is an allocation and copy.
  8. func stringView(v []byte) string {
  9. return string(v)
  10. }
  11. // bytesView returns a view of the string as a []byte.
  12. // In unsafe mode, it doesn't incur allocation and copying caused by conversion.
  13. // In regular safe mode, it is an allocation and copy.
  14. func bytesView(v string) []byte {
  15. return []byte(v)
  16. }