Skip to content

Commit c8beda0

Browse files
committed
Clean up implementation of UniqueSourceFileQueue
1 parent 3d88e16 commit c8beda0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

legacy/builder/types/accessories.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,23 @@ import "golang.org/x/exp/slices"
1919

2020
type UniqueSourceFileQueue []*SourceFile
2121

22-
func (queue UniqueSourceFileQueue) Len() int { return len(queue) }
23-
func (queue UniqueSourceFileQueue) Less(i, j int) bool { return false }
24-
func (queue UniqueSourceFileQueue) Swap(i, j int) { panic("Who called me?!?") }
25-
2622
func (queue *UniqueSourceFileQueue) Push(value *SourceFile) {
27-
equals := func(elem *SourceFile) bool {
28-
return elem.Origin == value.Origin && elem.RelativePath.EqualsTo(value.RelativePath)
29-
}
30-
if !slices.ContainsFunc(*queue, equals) {
23+
if !queue.Contains(value) {
3124
*queue = append(*queue, value)
3225
}
3326
}
3427

28+
func (queue UniqueSourceFileQueue) Contains(target *SourceFile) bool {
29+
return slices.ContainsFunc(queue, target.Equals)
30+
}
31+
3532
func (queue *UniqueSourceFileQueue) Pop() *SourceFile {
3633
old := *queue
3734
x := old[0]
3835
*queue = old[1:]
3936
return x
4037
}
4138

42-
func (queue *UniqueSourceFileQueue) Empty() bool {
43-
return queue.Len() == 0
39+
func (queue UniqueSourceFileQueue) Empty() bool {
40+
return len(queue) == 0
4441
}

legacy/builder/types/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type SourceFile struct {
3030
RelativePath *paths.Path
3131
}
3232

33+
func (f *SourceFile) Equals(g *SourceFile) bool {
34+
return f.Origin == g.Origin &&
35+
f.RelativePath.EqualsTo(g.RelativePath)
36+
}
37+
3338
// Create a SourceFile containing the given source file path within the
3439
// given origin. The given path can be absolute, or relative within the
3540
// origin's root source folder

0 commit comments

Comments
 (0)