d2/lib
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
..
background print msg when png and layout in progress 2023-03-18 15:29:46 -07:00
color lib/color: avoid unnecessary byte/string conversion 2023-10-18 23:30:11 +08:00
env configure timeout with D2_TIMEOUT 2023-06-12 15:46:38 -07:00
font Update subsetFont.go 2023-05-31 18:37:14 -07:00
geo inject nested graph, fit, spacing 2023-09-21 13:17:17 -07:00
imgbundler fmt 2023-06-06 11:33:00 -07:00
label user-specified label/icon positions 2023-06-22 19:17:56 -07:00
log move to timelib.WithTimeout 2023-06-14 13:06:40 -07:00
pdf Merge pull request #1204 from ejulio-ts/gh-1199-navbar 2023-04-17 16:06:17 -03:00
png Update generate_png.js 2023-04-13 13:40:58 -07:00
pptx navbar on pptx 2023-04-14 19:25:01 -03:00
shape fixes 2023-05-25 18:35:58 -07:00
svg move ThemableElement and others to d2themes, smaller fixes 2023-02-19 13:00:01 +01:00
textmeasure fix mixed md 2023-08-08 11:51:16 -07:00
time move to timelib.WithTimeout 2023-06-14 13:06:40 -07:00
urlenc new implementation 2023-07-11 17:19:34 -07:00
version bump d2 version to 0.6.1 2023-09-25 13:16:55 -07:00
xgif search for white index 2023-04-28 18:53:29 -03:00