about summary refs log tree commit diff stats
path: root/gomponents.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-10-29 15:40:14 +0100
committerGitHub2020-10-29 15:40:14 +0100
commit92ba5904c1645e6572f5ff1b9d0e0ec629e1afb9 (patch)
treea8152ee9fae45f724faf429c0bbd14c2ba62f15b /gomponents.go
parentf277d1942e9f2ec1ff4a3bc3c409e864103b506b (diff)
downloadgomponents-92ba5904c1645e6572f5ff1b9d0e0ec629e1afb9.tar.lz
gomponents-92ba5904c1645e6572f5ff1b9d0e0ec629e1afb9.tar.zst
gomponents-92ba5904c1645e6572f5ff1b9d0e0ec629e1afb9.zip
Remove fmt.Sprintf call in attribute Render (#38)
Just concatenating the strings is much faster.

Before:

```
make benchmark
go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/maragudk/gomponents
BenchmarkAttr/boolean_attributes-8         	 8194791	       139 ns/op
BenchmarkAttr/name-value_attributes-8      	 5143292	       229 ns/op
PASS
ok  	github.com/maragudk/gomponents	2.841s
```

After:

```
make benchmark
go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/maragudk/gomponents
BenchmarkAttr/boolean_attributes-8         	16755404	        67.0 ns/op
BenchmarkAttr/name-value_attributes-8      	10208625	       116 ns/op
PASS
ok  	github.com/maragudk/gomponents	2.702s
```
Diffstat (limited to 'gomponents.go')
-rw-r--r--gomponents.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/gomponents.go b/gomponents.go
index e6b89e1..f4b8467 100644
--- a/gomponents.go
+++ b/gomponents.go
@@ -129,9 +129,9 @@ type attr struct {
 
 func (a *attr) Render() string {
 	if a.value == nil {
-		return fmt.Sprintf(" %v", a.name)
+		return " " + a.name
 	}
-	return fmt.Sprintf(` %v="%v"`, a.name, *a.value)
+	return " " + a.name + `="` + *a.value + `"`
 }
 
 func (a *attr) Place() Placement {