Skip to content

Commit

Permalink
Moved util functions into util.go
Browse files Browse the repository at this point in the history
  • Loading branch information
valyala committed Jun 12, 2018
1 parent bb72c3a commit 53fb1e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
15 changes: 0 additions & 15 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"bytes"
"fmt"
"github.com/valyala/fastjson/fastfloat"
"reflect"
"strconv"
"strings"
"unsafe"
)

// Parser parses JSON.
Expand Down Expand Up @@ -73,19 +71,6 @@ func (c *cache) getValue() *Value {
return v
}

func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

func s2b(s string) []byte {
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
var sh reflect.SliceHeader
sh.Data = strh.Data
sh.Len = strh.Len
sh.Cap = strh.Len
return *(*[]byte)(unsafe.Pointer(&sh))
}

func skipWS(s string) string {
if len(s) == 0 || s[0] > 0x20 {
// Fast path.
Expand Down
19 changes: 19 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fastjson

import (
"reflect"
"unsafe"
)

func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

func s2b(s string) []byte {
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
var sh reflect.SliceHeader
sh.Data = strh.Data
sh.Len = strh.Len
sh.Cap = strh.Len
return *(*[]byte)(unsafe.Pointer(&sh))
}

0 comments on commit 53fb1e5

Please sign in to comment.