@@ -68,37 +68,41 @@ type responseData struct {
6868 Trans * i18n.Translation
6969}
7070
71- func isSlash (c rune ) bool {
72- return c == '/'
73- }
74-
7571func getPathEntries (currDirRelPath , path string , tailSlash bool ) []pathEntry {
76- restPaths := strings .FieldsFunc (path , isSlash )
77- paths := make ([]string , len (restPaths )+ 1 )
78- paths [0 ] = "/"
79- copy (paths [1 :], restPaths )
72+ pathSegs := make ([]string , 1 , 12 )
73+ pathSegs [0 ] = "/"
74+ for refPath := path [1 :]; len (refPath ) > 0 ; {
75+ slashIndex := strings .IndexByte (refPath , '/' )
76+ if slashIndex < 0 {
77+ pathSegs = append (pathSegs , refPath )
78+ break
79+ } else {
80+ pathSegs = append (pathSegs , refPath [:slashIndex ])
81+ refPath = refPath [slashIndex + 1 :]
82+ }
83+ }
8084
81- pathFrags := len (paths )
85+ pathCount := len (pathSegs )
8286
83- pathDepth := pathFrags
87+ pathDepth := pathCount
8488 if ! tailSlash {
8589 pathDepth --
8690 }
8791
88- pathEntries := make ([]pathEntry , pathFrags )
89- for n := 1 ; n <= pathFrags ; n ++ {
92+ pathEntries := make ([]pathEntry , pathCount )
93+ for n := 1 ; n <= pathCount ; n ++ {
9094 var relPath string
9195 if n < pathDepth {
9296 relPath = strings .Repeat ("../" , pathDepth - n )
9397 } else if n == pathDepth {
9498 relPath = currDirRelPath
9599 } else /*if n == pathDepth+1*/ {
96- relPath = currDirRelPath + paths [pathDepth ] + "/"
100+ relPath = currDirRelPath + pathSegs [pathDepth ] + "/"
97101 }
98102
99103 i := n - 1
100104 pathEntries [i ] = pathEntry {
101- Name : paths [i ],
105+ Name : pathSegs [i ],
102106 Path : relPath ,
103107 }
104108 }
0 commit comments