diff --git a/bytes.go b/bytes.go new file mode 100644 index 00000000..3944bfe1 --- /dev/null +++ b/bytes.go @@ -0,0 +1,14 @@ +// +build !appengine + +package bigcache + +import ( + "reflect" + "unsafe" +) + +func bytesToString(b []byte) string { + bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + strHeader := reflect.StringHeader{Data: bytesHeader.Data, Len: bytesHeader.Len} + return *(*string)(unsafe.Pointer(&strHeader)) +} diff --git a/bytes_appengine.go b/bytes_appengine.go new file mode 100644 index 00000000..3892f3b5 --- /dev/null +++ b/bytes_appengine.go @@ -0,0 +1,7 @@ +// +build appengine + +package bigcache + +func bytesToString(b []byte) string { + return string(b) +} diff --git a/encoding.go b/encoding.go index 5d90d71d..4d434e5d 100644 --- a/encoding.go +++ b/encoding.go @@ -2,8 +2,6 @@ package bigcache import ( "encoding/binary" - "reflect" - "unsafe" ) const ( @@ -55,12 +53,6 @@ func readKeyFromEntry(data []byte) string { return bytesToString(dst) } -func bytesToString(b []byte) string { - bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - strHeader := reflect.StringHeader{Data: bytesHeader.Data, Len: bytesHeader.Len} - return *(*string)(unsafe.Pointer(&strHeader)) -} - func readHashFromEntry(data []byte) uint64 { return binary.LittleEndian.Uint64(data[timestampSizeInBytes:]) }