2016-09-23 00:04:49 +00:00
|
|
|
package models // import "github.com/influxdata/influxdb/models"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2016-09-21 17:12:09 +00:00
|
|
|
// parseIntBytes is a zero-alloc wrapper around strconv.ParseInt.
|
|
|
|
func parseIntBytes(b []byte, base int, bitSize int) (i int64, err error) {
|
2016-09-23 00:04:49 +00:00
|
|
|
s := unsafeBytesToString(b)
|
|
|
|
return strconv.ParseInt(s, base, bitSize)
|
|
|
|
}
|
|
|
|
|
2017-06-06 07:40:38 +00:00
|
|
|
// parseUintBytes is a zero-alloc wrapper around strconv.ParseUint.
|
|
|
|
func parseUintBytes(b []byte, base int, bitSize int) (i uint64, err error) {
|
|
|
|
s := unsafeBytesToString(b)
|
|
|
|
return strconv.ParseUint(s, base, bitSize)
|
|
|
|
}
|
|
|
|
|
2016-09-21 17:12:09 +00:00
|
|
|
// parseFloatBytes is a zero-alloc wrapper around strconv.ParseFloat.
|
|
|
|
func parseFloatBytes(b []byte, bitSize int) (float64, error) {
|
2016-09-23 00:04:49 +00:00
|
|
|
s := unsafeBytesToString(b)
|
|
|
|
return strconv.ParseFloat(s, bitSize)
|
|
|
|
}
|
|
|
|
|
2016-09-21 17:12:09 +00:00
|
|
|
// parseBoolBytes is a zero-alloc wrapper around strconv.ParseBool.
|
|
|
|
func parseBoolBytes(b []byte) (bool, error) {
|
|
|
|
return strconv.ParseBool(unsafeBytesToString(b))
|
|
|
|
}
|
|
|
|
|
2016-09-23 00:04:49 +00:00
|
|
|
// unsafeBytesToString converts a []byte to a string without a heap allocation.
|
|
|
|
func unsafeBytesToString(in []byte) string {
|
2021-11-24 17:47:26 +00:00
|
|
|
return *(*string)(unsafe.Pointer(&in))
|
2016-09-23 00:04:49 +00:00
|
|
|
}
|