aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-05-06 20:45:06 +0700
committerShulhan <m.shulhan@gmail.com>2020-05-06 20:45:06 +0700
commit52c75cf627fa5acf5ad63152382a22e7d7e59481 (patch)
tree1d0087151cb59159670eefba6e1a990f861d3b13 /lib
parent1d3be6be00d706c86ffca88aac19cfeb874dd91e (diff)
downloadpakakeh.go-52c75cf627fa5acf5ad63152382a22e7d7e59481.tar.xz
memfs: replace the contents values from list of byte to string
Previously the generated asset's content is encoded as numeric, which may slowing down parser and compiler. For example, if the file content is "Hello" it will generated as []byte{72, 101, 108, 108, 111} This commit changes the generated content using escaped hex code, []byte("\x48\x65\x6c\x6c\x6f")
Diffstat (limited to 'lib')
-rw-r--r--lib/memfs/template.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/memfs/template.go b/lib/memfs/template.go
index 85f42178..e250d013 100644
--- a/lib/memfs/template.go
+++ b/lib/memfs/template.go
@@ -52,16 +52,14 @@ import (
)
{{end}}
{{define "GENERATE_NODE"}}
-func generate{{ funcname .Path | printf "%s"}}() *memfs.Node {
+func generate{{ funcname .Path}}() *memfs.Node {
node := &memfs.Node{
SysPath: "{{.SysPath}}",
Path: "{{.Path}}",
ContentType: "{{.ContentType}}",
ContentEncoding: "{{.ContentEncoding}}",
{{- if .V }}
- V: []byte{
- {{range $x, $c := .V}}{{ if maxline $x }}{{ printf "\n\t\t\t" }}{{else if $x}} {{end}}{{ printf "%d," $c }}{{end}}
- },
+ V: []byte("{{range $x, $c := .V}}{{ printf "\\x%x" $c }}{{end}}"),
{{- end }}
}
node.SetMode({{printf "%d" .Mode}})
@@ -74,14 +72,16 @@ func generate{{ funcname .Path | printf "%s"}}() *memfs.Node {
func init() {
memfs.GeneratedPathNode = memfs.NewPathNode()
{{- range $path, $node := .}}
- memfs.GeneratedPathNode.Set("{{$path}}", generate{{funcname $node.Path | printf "%s" }}())
+ memfs.GeneratedPathNode.Set("{{$path}}", generate{{funcname $node.Path}}())
{{- end}}
}
{{end}}
`
tmplFuncs := template.FuncMap{
- "funcname": func(path string) []byte {
- return libbytes.InReplace([]byte(path), []byte(ascii.LettersNumber), '_')
+ "funcname": func(path string) string {
+ return string(
+ libbytes.InReplace([]byte(path),
+ []byte(ascii.LettersNumber), '_'))
},
"maxline": func(x int) bool {
if x != 0 && x%16 == 0 {