Commit graph

22 commits

Author SHA1 Message Date
Eng Zer Jun
5c2d468058
lib/color: avoid unnecessary byte/string conversion
We can use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` to avoid unnecessary `[]byte`
conversions and reduce allocations.

Example benchmark:

func BenchmarkMatch(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := themeColorRegex.Match([]byte("N1")); !match {
			b.Fail()
		}
	}
}

func BenchmarkMatchString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := themeColorRegex.MatchString("N1"); !match {
			b.Fail()
		}
	}
}

goos: linux
goarch: amd64
pkg: oss.terrastruct.com/d2/lib/color
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16          	 9894165	       114.3 ns/op	       2 B/op	       1 allocs/op
BenchmarkMatchString-16    	13439838	        83.61 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	oss.terrastruct.com/d2/lib/color	3.306s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-10-18 23:30:11 +08:00
Bernard Xie
2292ed4653
Update color.go 2023-02-27 16:46:44 -08:00
Bernard Xie
d72068d194
Update color.go 2023-02-27 16:45:25 -08:00
Bernard Xie
3427ea1717
w3 official source 2023-02-27 16:38:48 -08:00
Bernard Xie
2fb0df3563
add rebecca purple 2023-02-27 16:34:44 -08:00
Bernard Xie
8e0feef0da
color comment 2023-02-27 16:30:25 -08:00
Bernard Xie
7c295c1942
to lower on name2rgb 2023-02-27 16:27:28 -08:00
Bernard Xie
b48c2b411f
Update color.go 2023-02-27 16:22:10 -08:00
Bernard Xie
63ffcba215
error 2023-02-27 16:10:00 -08:00
Bernard Xie
66083e2d98
set root fill as transparent on pdf exports 2023-02-27 16:05:41 -08:00
Bernard Xie
29e76b77b8
Merge branch 'master' into support-diagram-fill-pdf 2023-02-27 14:11:07 -08:00
Bernard Xie
fb4eb36214
Add support 2023-02-27 14:10:59 -08:00
Alexander Wang
9cdfd20ff9
changelog 2023-02-27 12:58:21 -08:00
Alexander Wang
e5eacbd499
fix theme regex 2023-02-27 12:56:04 -08:00
Alexander Wang
0fe1c6d0cf
fix color codes 2023-02-23 17:15:29 -08:00
Vojtěch Fošnár
732f5c241f
bgColor and fgColor are now just constants 2023-02-19 15:54:17 +01:00
Vojtěch Fošnár
01928a5032
review fixes 2023-01-30 12:06:54 +01:00
Vojtěch Fošnár
19c53d5185
added missing colors conversion 2023-01-12 11:19:34 +01:00
Vojtěch Fošnár
63a0c1e2b1
vary sketch overlay color depending on the background and small refactoring 2023-01-11 22:18:14 +01:00
Vojtěch Fošnár
84e8c25e37
implemented (limited) darkening of theme colors and fixed rendering of the 3D box 2023-01-09 22:50:17 +01:00
Vojtěch Fošnár
a81ab2d73e
support for prefers-color-scheme 2023-01-09 19:16:28 +01:00
Gavin Nishizawa
8cc5e733f9 render 3d keyword 2022-11-10 11:36:32 -08:00