this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mst: remove an alloc in isValidMstKey (#144)

goos: darwin
goarch: arm64
pkg: github.com/bluesky-social/indigo/mst
│ before │ after │
│ sec/op │ sec/op vs base │
IsValidMstKey-8 301.1n ± 4% 262.8n ± 4% -12.69% (p=0.000 n=10)

│ before │ after │
│ B/op │ B/op vs base │
IsValidMstKey-8 32.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10)

│ before │ after │
│ allocs/op │ allocs/op vs base │
IsValidMstKey-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)

authored by

Whyrusleeping and committed by
GitHub
4508f3e4 2311acc0

+17 -7
+9
mst/mst_test.go
··· 502 502 } 503 503 return true 504 504 } 505 + 506 + func BenchmarkIsValidMstKey(b *testing.B) { 507 + b.ReportAllocs() 508 + for i := 0; i < b.N; i++ { 509 + if !isValidMstKey("foo/foo.bar123") { 510 + b.Fatal() 511 + } 512 + } 513 + }
+8 -7
mst/mst_util.go
··· 193 193 194 194 // Typescript: isValidMstKey(str) 195 195 func isValidMstKey(s string) bool { 196 - split := strings.Split(s, "/") 197 - return (len(s) <= 256 && 198 - len(split) == 2 && 199 - len(split[0]) > 0 && 200 - len(split[1]) > 1 && 201 - reMstKeyChars.MatchString(split[0]) && 202 - reMstKeyChars.MatchString(split[1])) 196 + if len(s) > 256 || strings.Count(s, "/") != 1 { 197 + return false 198 + } 199 + a, b, _ := strings.Cut(s, "/") 200 + return len(a) > 0 && 201 + len(b) > 1 && 202 + reMstKeyChars.MatchString(a) && 203 + reMstKeyChars.MatchString(b) 203 204 } 204 205 205 206 // Typescript: ensureValidMstKey(str)