this repo has no description

appview: reduce allocations in router

regexes were recompiled on each router visit.

Signed-off-by: oppiliappan <me@oppi.li>

Changed files
+10 -7
appview
state
userutil
+8 -6
appview/state/userutil/userutil.go
··· 5 "strings" 6 ) 7 8 func IsHandleNoAt(s string) bool { 9 // ref: https://atproto.com/specs/handle 10 - re := regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`) 11 - return re.MatchString(s) 12 } 13 14 func UnflattenDid(s string) string { ··· 29 // Reconstruct as a standard DID format using Replace 30 // Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc" 31 reconstructed := strings.Replace(s, "-", ":", 2) 32 - re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`) 33 34 - return re.MatchString(reconstructed) 35 } 36 37 // FlattenDid converts a DID to a flattened format. ··· 46 47 // IsDid checks if the given string is a standard DID. 48 func IsDid(s string) bool { 49 - re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`) 50 - return re.MatchString(s) 51 }
··· 5 "strings" 6 ) 7 8 + var ( 9 + handleRegex = regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`) 10 + didRegex = regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`) 11 + ) 12 + 13 func IsHandleNoAt(s string) bool { 14 // ref: https://atproto.com/specs/handle 15 + return handleRegex.MatchString(s) 16 } 17 18 func UnflattenDid(s string) string { ··· 33 // Reconstruct as a standard DID format using Replace 34 // Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc" 35 reconstructed := strings.Replace(s, "-", ":", 2) 36 37 + return didRegex.MatchString(reconstructed) 38 } 39 40 // FlattenDid converts a DID to a flattened format. ··· 49 50 // IsDid checks if the given string is a standard DID. 51 func IsDid(s string) bool { 52 + return didRegex.MatchString(s) 53 }
+2 -1
flake.nix
··· 150 '' 151 ${pkgs.air}/bin/air -c /dev/null \ 152 -build.cmd "${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \ 153 - -build.bin "./out/${name}.out ${arg}" \ 154 -build.stop_on_error "true" \ 155 -build.include_ext "go" 156 '';
··· 150 '' 151 ${pkgs.air}/bin/air -c /dev/null \ 152 -build.cmd "${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \ 153 + -build.bin "./out/${name}.out" \ 154 + -build.args_bin "${arg}" 155 -build.stop_on_error "true" \ 156 -build.include_ext "go" 157 '';