Skip to content

Commit

Permalink
opt: use native or std func
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Feb 12, 2024
1 parent 9f8210b commit ed746bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
50 changes: 24 additions & 26 deletions internal/encoder/alg/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,31 @@ func HtmlEscape(dst []byte, src []byte) []byte {
return dst
}

// func F64toa(buf []byte, v float64) ([]byte) {
// buf = rt.GuardSlice2(buf, 64)
// ret := native.F64toa((*byte)(rt.IndexByte(buf, len(buf))), v)
// if ret > 0 {
// return buf[:len(buf)+ret]
// } else {
// return buf
// }
// }
func F64toa(buf []byte, v float64) ([]byte) {
if v == 0 {
return append(buf, '0')
}
buf = rt.GuardSlice2(buf, 64)
ret := native.F64toa((*byte)(rt.IndexByte(buf, len(buf))), v)
if ret > 0 {
return buf[:len(buf)+ret]
} else {
return buf
}
}

// func F32toa(buf []byte, v float32) ([]byte) {
// buf = rt.GuardSlice2(buf, 64)
// ret := native.F32toa((*byte)(rt.IndexByte(buf, len(buf))), v)
// if ret > 0 {
// return buf[:len(buf)+ret]
// } else {
// return buf
// }
// }
func F32toa(buf []byte, v float32) ([]byte) {
if v == 0 {
return append(buf, '0')
}
buf = rt.GuardSlice2(buf, 64)
ret := native.F32toa((*byte)(rt.IndexByte(buf, len(buf))), v)
if ret > 0 {
return buf[:len(buf)+ret]
} else {
return buf
}
}

// func I64toa(buf []byte, v int64) ([]byte) {
// if -10 < v && v < 10 {
Expand Down Expand Up @@ -199,14 +205,6 @@ func HtmlEscape(dst []byte, src []byte) []byte {
// }
// }

func F64toa(buf []byte, v float64) ([]byte) {
return strconv.AppendFloat(buf, float64(v), 'g', -1, 64)
}

func F32toa(buf []byte, v float32) ([]byte) {
return strconv.AppendFloat(buf, float64(v), 'g', -1, 32)
}

func I64toa(buf []byte, v int64) ([]byte) {
return strconv.AppendInt(buf, int64(v), 10)
}
Expand Down
13 changes: 8 additions & 5 deletions internal/native/neon/fastfloat_arm64_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed746bd

Please sign in to comment.