forked from tangled.org/core
this repo has no description

appview: reduce allocations in router

regexes were recompiled on each router visit.

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

oppi.li 256c0339 7c12eebe

verified
Changed files
+10 -7
appview
state
userutil
+8 -6
appview/state/userutil/userutil.go
···
"strings"
)
func IsHandleNoAt(s string) bool {
// ref: https://atproto.com/specs/handle
-
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])?$`)
-
return re.MatchString(s)
}
func UnflattenDid(s string) string {
···
// Reconstruct as a standard DID format using Replace
// Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc"
reconstructed := strings.Replace(s, "-", ":", 2)
-
re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
-
return re.MatchString(reconstructed)
}
// FlattenDid converts a DID to a flattened format.
···
// IsDid checks if the given string is a standard DID.
func IsDid(s string) bool {
-
re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
-
return re.MatchString(s)
}
···
"strings"
)
+
var (
+
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])?$`)
+
didRegex = regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
+
)
+
func IsHandleNoAt(s string) bool {
// ref: https://atproto.com/specs/handle
+
return handleRegex.MatchString(s)
}
func UnflattenDid(s string) string {
···
// Reconstruct as a standard DID format using Replace
// Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc"
reconstructed := strings.Replace(s, "-", ":", 2)
+
return didRegex.MatchString(reconstructed)
}
// FlattenDid converts a DID to a flattened format.
···
// IsDid checks if the given string is a standard DID.
func IsDid(s string) bool {
+
return didRegex.MatchString(s)
}
+2 -1
flake.nix
···
''
${pkgs.air}/bin/air -c /dev/null \
-build.cmd "${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \
-
-build.bin "./out/${name}.out ${arg}" \
-build.stop_on_error "true" \
-build.include_ext "go"
'';
···
''
${pkgs.air}/bin/air -c /dev/null \
-build.cmd "${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \
+
-build.bin "./out/${name}.out" \
+
-build.args_bin "${arg}"
-build.stop_on_error "true" \
-build.include_ext "go"
'';