Extract ParseKeyBytes from ParseKey

Allows callers to use []byte and avoid a string allocation
pull/9084/head
Jason Wilder 2017-10-23 12:24:40 -06:00
parent 6b19d2b673
commit de5592cda9
1 changed files with 7 additions and 2 deletions

View File

@ -263,6 +263,11 @@ func ParsePointsString(buf string) ([]Point, error) {
// NOTE: to minimize heap allocations, the returned Tags will refer to subslices of buf.
// This can have the unintended effect preventing buf from being garbage collected.
func ParseKey(buf []byte) (string, Tags) {
meas, tags := ParseKeyBytes(buf)
return string(meas), tags
}
func ParseKeyBytes(buf []byte) ([]byte, Tags) {
// Ignore the error because scanMeasurement returns "missing fields" which we ignore
// when just parsing a key
state, i, _ := scanMeasurement(buf, 0)
@ -271,9 +276,9 @@ func ParseKey(buf []byte) (string, Tags) {
if state == tagKeyState {
tags = parseTags(buf)
// scanMeasurement returns the location of the comma if there are tags, strip that off
return string(buf[:i-1]), tags
return buf[:i-1], tags
}
return string(buf[:i]), tags
return buf[:i], tags
}
func ParseTags(buf []byte) (Tags, error) {