72c92672b7
Use sliced arrays to reduce the amount of null padding in template fragments. Revert a failed optimisation in templates. Remove a few more redundant branches in variant templates. Added the unsafe function StringToBytes. Added BenchmarkTopicGuestRouteParallelWithRouterAlt.
26 lines
449 B
Go
26 lines
449 B
Go
package tmpl
|
|
|
|
import (
|
|
"reflect"
|
|
"runtime"
|
|
"unsafe"
|
|
)
|
|
|
|
var GetFrag = func(name string) [][]byte {
|
|
return nil
|
|
}
|
|
|
|
type WriteString interface {
|
|
WriteString(s string) (n int, err error)
|
|
}
|
|
|
|
func StringToBytes(s string) (bytes []byte) {
|
|
str := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
|
slice := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
|
|
slice.Data = str.Data
|
|
slice.Len = str.Len
|
|
slice.Cap = str.Len
|
|
runtime.KeepAlive(&s)
|
|
return bytes
|
|
}
|