diff --git a/pkg/app/html.go b/pkg/app/html.go index a86ee6ed7..d598c9ee3 100644 --- a/pkg/app/html.go +++ b/pkg/app/html.go @@ -1,7 +1,6 @@ package app import ( - "bufio" "context" "io" "net/url" @@ -330,95 +329,89 @@ func (e *htmlElement) preRender(p Page) { } func (e *htmlElement) html(w io.Writer) { - bw := bufio.NewWriter(w) - defer bw.Flush() - - bw.WriteString("<") - bw.WriteString(e.tag) + w.Write([]byte("<")) + w.Write([]byte(e.tag)) for k, v := range e.attributes { - bw.WriteString(" ") - bw.WriteString(k) + w.Write([]byte(" ")) + w.Write([]byte(k)) if v != "" { - bw.WriteString(`="`) - bw.WriteString(resolveAttributeURLValue(k, v, func(s string) string { + w.Write([]byte(`="`)) + w.Write([]byte(resolveAttributeURLValue(k, v, func(s string) string { if e.dispatcher != nil { return e.dispatcher.resolveStaticResource(v) } return v - })) - bw.WriteString(`"`) + }))) + w.Write([]byte(`"`)) } } - bw.WriteString(">") + w.Write([]byte(">")) if e.isSelfClosing { return } for _, c := range e.children { - bw.WriteString("n") + w.Write(ln()) if c.self() == nil { c.setSelf(c) } - c.html(bw) + c.html(w) } if len(e.children) != 0 { - bw.WriteString("\n") + w.Write(ln()) } - bw.WriteString("") + w.Write([]byte("")) } func (e *htmlElement) htmlWithIndent(w io.Writer, indent int) { - bw := bufio.NewWriter(w) - defer bw.Flush() - writeIndent(w, indent) - bw.WriteString("<") - bw.WriteString(e.tag) + w.Write([]byte("<")) + w.Write([]byte(e.tag)) for k, v := range e.attributes { - bw.WriteString(" ") - bw.WriteString(k) + w.Write([]byte(" ")) + w.Write([]byte(k)) if v != "" { - bw.WriteString(`="`) - bw.WriteString(resolveAttributeURLValue(k, v, func(s string) string { + w.Write([]byte(`="`)) + w.Write([]byte(resolveAttributeURLValue(k, v, func(s string) string { if e.dispatcher != nil { return e.dispatcher.resolveStaticResource(v) } return v - })) - bw.WriteString(`"`) + }))) + w.Write([]byte(`"`)) } } - bw.WriteString(">") + w.Write([]byte(">")) if e.isSelfClosing { return } for _, c := range e.children { - bw.WriteString("\n") + w.Write(ln()) if c.self() == nil { c.setSelf(c) } - c.htmlWithIndent(bw, indent+1) + c.htmlWithIndent(w, indent+1) } if len(e.children) != 0 { - bw.WriteString("\n") - writeIndent(bw, indent) + w.Write(ln()) + writeIndent(w, indent) } - bw.WriteString("") + w.Write([]byte("")) } diff --git a/pkg/app/html_test.go b/pkg/app/html_test.go index 9ae178296..58689620b 100644 --- a/pkg/app/html_test.go +++ b/pkg/app/html_test.go @@ -1,7 +1,6 @@ package app import ( - "bytes" "fmt" "testing" ) @@ -25,47 +24,3 @@ func BenchmarkMountHTMLElement(b *testing.B) { client.Close() } } - -func BenchmarkHTMLElementHTML(b *testing.B) { - div := Div(). - Class("shell"). - Body( - H1().Class("title"). - Text("Hello"), - Input(). - Type("text"). - Class("in"). - Value("World"). - Placeholder("Type a name."). - OnChange(func(ctx Context, e Event) { - fmt.Println("Yo!") - }), - ) - - for n := 0; n < b.N; n++ { - var bytes bytes.Buffer - div.html(&bytes) - } -} - -func BenchmarkHTMLElementHTMLIndent(b *testing.B) { - div := Div(). - Class("shell"). - Body( - H1().Class("title"). - Text("Hello"), - Input(). - Type("text"). - Class("in"). - Value("World"). - Placeholder("Type a name."). - OnChange(func(ctx Context, e Event) { - fmt.Println("Yo!") - }), - ) - - for n := 0; n < b.N; n++ { - var bytes bytes.Buffer - div.htmlWithIndent(&bytes, 0) - } -} diff --git a/pkg/app/strings.go b/pkg/app/strings.go index c8da211ed..4e13714a6 100644 --- a/pkg/app/strings.go +++ b/pkg/app/strings.go @@ -1,7 +1,6 @@ package app import ( - "bufio" "encoding/json" "fmt" "io" @@ -53,11 +52,8 @@ func toPath(v ...any) string { } func writeIndent(w io.Writer, indent int) { - bw := bufio.NewWriter(w) - defer bw.Flush() - for i := 0; i < indent*2; i++ { - bw.WriteString(" ") + w.Write([]byte(" ")) } }