Skip to content

Commit 967d010

Browse files
committed
Factored sliceContainsSourceFile into a proper method
1 parent e334061 commit 967d010

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

legacy/builder/types/accessories.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ func (queue UniqueSourceFileQueue) Less(i, j int) bool { return false }
5050
func (queue UniqueSourceFileQueue) Swap(i, j int) { panic("Who called me?!?") }
5151

5252
func (queue *UniqueSourceFileQueue) Push(value *SourceFile) {
53-
if !sliceContainsSourceFile(*queue, value) {
53+
if !queue.Contains(value) {
5454
*queue = append(*queue, value)
5555
}
5656
}
5757

58+
func (queue UniqueSourceFileQueue) Contains(target *SourceFile) bool {
59+
for _, elem := range queue {
60+
if elem.Equals(target) {
61+
return true
62+
}
63+
}
64+
return false
65+
}
66+
5867
func (queue *UniqueSourceFileQueue) Pop() *SourceFile {
5968
old := *queue
6069
x := old[0]

legacy/builder/types/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type SourceFile struct {
3131
RelativePath *paths.Path
3232
}
3333

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

legacy/builder/types/utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,3 @@ func sliceContains(slice []string, target string) bool {
2424
}
2525
return false
2626
}
27-
28-
func sliceContainsSourceFile(slice []SourceFile, target *SourceFile) bool {
29-
for _, elem := range slice {
30-
if elem.Origin == target.Origin && elem.RelativePath.EqualsTo(target.RelativePath) {
31-
return true
32-
}
33-
}
34-
return false
35-
}

0 commit comments

Comments
 (0)