Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/modulespecifiers/specifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ func getAllModulePathsWorker(
allFileNames[p.FileName] = p
}

useCaseSensitiveFileNames := info.UseCaseSensitiveFileNames
comparePaths := func(a, b ModulePath) int {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually allocate, right? I assume it'll keep everything on the stack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, or at worst it'll be a single slot on the stack for the closure object

return comparePathsByRedirect(a, b, useCaseSensitiveFileNames)
}

// Sort by paths closest to importing file Name directory
sortedPaths := make([]ModulePath, 0, len(paths))
for directory := info.SourceDirectory; len(allFileNames) != 0; {
Expand All @@ -220,7 +225,7 @@ func getAllModulePathsWorker(
}
}
if len(pathsInDirectory) > 0 {
slices.SortStableFunc(pathsInDirectory, comparePathsByRedirectAndNumberOfDirectorySeparators)
slices.SortFunc(pathsInDirectory, comparePaths)
sortedPaths = append(sortedPaths, pathsInDirectory...)
}
newDirectory := tspath.GetDirectoryPath(directory)
Expand All @@ -231,7 +236,7 @@ func getAllModulePathsWorker(
}
if len(allFileNames) > 0 {
remainingPaths := slices.Collect(maps.Values(allFileNames))
slices.SortStableFunc(remainingPaths, comparePathsByRedirectAndNumberOfDirectorySeparators)
slices.SortFunc(remainingPaths, comparePaths)
sortedPaths = append(sortedPaths, remainingPaths...)
}
return sortedPaths
Expand Down
4 changes: 2 additions & 2 deletions internal/modulespecifiers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var (
regexPatternCache = make(map[regexPatternCacheKey]*regexp2.Regexp)
)

func comparePathsByRedirectAndNumberOfDirectorySeparators(a ModulePath, b ModulePath) int {
func comparePathsByRedirect(a ModulePath, b ModulePath, useCaseSensitiveFileNames bool) int {
if a.IsRedirect == b.IsRedirect {
return strings.Count(a.FileName, "/") - strings.Count(b.FileName, "/")
return tspath.ComparePaths(a.FileName, b.FileName, tspath.ComparePathsOptions{UseCaseSensitiveFileNames: useCaseSensitiveFileNames})
}
if a.IsRedirect {
return 1
Expand Down