Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

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

reporesolver: compile path regexps at package init

Move blobPattern, treePattern, and pathAfterRefRE to package-level
vars so they are compiled once and reused across GetRepoInfo and
path resolution calls instead of recompiling on every request.

Signed-off-by: Matías Insaurralde <matias@insaurral.de>

authored by

Matías Insaurralde and committed by tangled.org 6b3ca476 e326cc53

+9 -9
+9 -9
appview/reporesolver/resolver.go
··· 18 18 "tangled.org/core/rbac" 19 19 ) 20 20 21 + var ( 22 + blobPattern = regexp.MustCompile(`blob/[^/]+/(.*)$`) 23 + treePattern = regexp.MustCompile(`tree/[^/]+/(.*)$`) 24 + pathAfterRefRE = regexp.MustCompile(`(?:blob|tree|raw)/[^/]+/(.*)$`) 25 + ) 26 + 21 27 type RepoResolver struct { 22 28 config *config.Config 23 29 enforcer *rbac.Enforcer ··· 146 140 func extractCurrentDir(fullPath string) string { 147 141 fullPath = strings.TrimPrefix(fullPath, "/") 148 142 149 - blobPattern := regexp.MustCompile(`blob/[^/]+/(.*)$`) 150 143 if matches := blobPattern.FindStringSubmatch(fullPath); len(matches) > 1 { 151 144 return path.Dir(matches[1]) 152 145 } 153 146 154 - treePattern := regexp.MustCompile(`tree/[^/]+/(.*)$`) 155 147 if matches := treePattern.FindStringSubmatch(fullPath); len(matches) > 1 { 156 148 dir := strings.TrimSuffix(matches[1], "/") 157 149 if dir == "" { ··· 168 164 func extractPathAfterRef(fullPath string) string { 169 165 fullPath = strings.TrimPrefix(fullPath, "/") 170 166 171 - // match blob/, tree/, or raw/ followed by any ref and then a slash 172 - // 173 - // captures everything after the final slash 174 - pattern := `(?:blob|tree|raw)/[^/]+/(.*)$` 175 - 176 - re := regexp.MustCompile(pattern) 177 - matches := re.FindStringSubmatch(fullPath) 167 + // pathAfterRefRE matches blob/, tree/, or raw/ followed by any ref and then a slash; 168 + // it captures everything after the final slash. 169 + matches := pathAfterRefRE.FindStringSubmatch(fullPath) 178 170 179 171 if len(matches) > 1 { 180 172 return matches[1]