@@ -125,10 +125,10 @@ func searchKeys(data []byte, keys ...string) int {
125125
126126 // if string is a Key, and key level match
127127 if data [i ] == ':' {
128- candidateKey := data [keyBegin :keyEnd ]
128+ key := data [keyBegin :keyEnd ]
129129
130130 if keyLevel == level - 1 && // If key nesting level match current object nested level
131- BytesEqualStr ( & candidateKey , keys [level - 1 ]) {
131+ equalStr ( & key , keys [level - 1 ]) {
132132 keyLevel ++
133133 // If we found all keys in path
134134 if keyLevel == lk {
@@ -341,6 +341,17 @@ func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int
341341 return nil
342342}
343343
344+ // GetUnsafeString returns the value retrieved by `Get`, use creates string without memory allocation by mapping string to slice memory. It does not handle escape symbols.
345+ func GetUnsafeString (data []byte , keys ... string ) (val string , err error ) {
346+ v , _ , _ , e := Get (data , keys ... )
347+
348+ if e != nil {
349+ return "" , e
350+ }
351+
352+ return bytesToString (& v ), nil
353+ }
354+
344355// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
345356// If key data type do not match, it will return an error.
346357func GetString (data []byte , keys ... string ) (val string , err error ) {
@@ -378,7 +389,7 @@ func GetFloat(data []byte, keys ...string) (val float64, err error) {
378389 return 0 , fmt .Errorf ("Value is not a number: %s" , string (v ))
379390 }
380391
381- val , err = BytesParseFloat (& v , 64 )
392+ val , err = parseFloat (& v )
382393 return
383394}
384395
@@ -395,7 +406,7 @@ func GetInt(data []byte, keys ...string) (val int64, err error) {
395406 return 0 , fmt .Errorf ("Value is not a number: %s" , string (v ))
396407 }
397408
398- if val , ok := BytesParseInt (v ); ! ok {
409+ if val , ok := parseInt (v ); ! ok {
399410 return 0 , MalformedValueError
400411 } else {
401412 return val , nil
0 commit comments