Skip to content

Commit 4298a66

Browse files
committed
Moved uniqueSourceFileQueue in his own file
1 parent 00db9e3 commit 4298a66

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

internal/arduino/builder/internal/detector/detector.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"fmt"
2424
"os/exec"
2525
"regexp"
26-
"slices"
2726
"strings"
2827
"time"
2928

@@ -259,15 +258,15 @@ func (l *SketchLibrariesDetector) findIncludes(
259258
if err != nil {
260259
return err
261260
}
262-
sourceFileQueue.push(mergedfile)
261+
sourceFileQueue.Push(mergedfile)
263262

264263
l.queueSourceFilesFromFolder(sourceFileQueue, sketchBuildPath, false /* recurse */, sketchBuildPath, sketchBuildPath)
265264
srcSubfolderPath := sketchBuildPath.Join("src")
266265
if srcSubfolderPath.IsDir() {
267266
l.queueSourceFilesFromFolder(sourceFileQueue, srcSubfolderPath, true /* recurse */, sketchBuildPath, sketchBuildPath)
268267
}
269268

270-
for !sourceFileQueue.empty() {
269+
for !sourceFileQueue.Empty() {
271270
err := l.findIncludesUntilDone(ctx, cache, sourceFileQueue, buildProperties, librariesBuildPath, platformArch)
272271
if err != nil {
273272
cachePath.Remove()
@@ -303,7 +302,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
303302
librariesBuildPath *paths.Path,
304303
platformArch string,
305304
) error {
306-
sourceFile := sourceFileQueue.pop()
305+
sourceFile := sourceFileQueue.Pop()
307306
sourcePath := sourceFile.SourcePath()
308307
targetFilePath := paths.NullPath()
309308
depPath := sourceFile.DepfilePath()
@@ -443,7 +442,7 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
443442
if err != nil {
444443
return err
445444
}
446-
sourceFileQueue.push(sourceFile)
445+
sourceFileQueue.Push(sourceFile)
447446
}
448447

449448
return nil
@@ -687,26 +686,3 @@ func writeCache(cache *includeCache, path *paths.Path) error {
687686
}
688687
return nil
689688
}
690-
691-
type uniqueSourceFileQueue []*sourceFile
692-
693-
func (queue *uniqueSourceFileQueue) push(value *sourceFile) {
694-
if !queue.contains(value) {
695-
*queue = append(*queue, value)
696-
}
697-
}
698-
699-
func (queue uniqueSourceFileQueue) contains(target *sourceFile) bool {
700-
return slices.ContainsFunc(queue, target.Equals)
701-
}
702-
703-
func (queue *uniqueSourceFileQueue) pop() *sourceFile {
704-
old := *queue
705-
x := old[0]
706-
*queue = old[1:]
707-
return x
708-
}
709-
710-
func (queue uniqueSourceFileQueue) empty() bool {
711-
return len(queue) == 0
712-
}

internal/arduino/builder/internal/detector/source_file.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
package detector
1717

18-
import "github.com/arduino/go-paths-helper"
18+
import (
19+
"slices"
20+
21+
"github.com/arduino/go-paths-helper"
22+
)
1923

2024
type sourceFile struct {
2125
// Path to the source file within the sketch/library root folder
@@ -90,3 +94,31 @@ func (f *sourceFile) ObjectPath() *paths.Path {
9094
func (f *sourceFile) DepfilePath() *paths.Path {
9195
return f.buildRoot.Join(f.relativePath.String() + ".d")
9296
}
97+
98+
// uniqueSourceFileQueue is a queue of source files that does not allow duplicates.
99+
type uniqueSourceFileQueue []*sourceFile
100+
101+
// Push adds a source file to the queue if it is not already present.
102+
func (queue *uniqueSourceFileQueue) Push(value *sourceFile) {
103+
if !queue.Contains(value) {
104+
*queue = append(*queue, value)
105+
}
106+
}
107+
108+
// Contains checks if the queue Contains a source file.
109+
func (queue uniqueSourceFileQueue) Contains(target *sourceFile) bool {
110+
return slices.ContainsFunc(queue, target.Equals)
111+
}
112+
113+
// Pop removes and returns the first element of the queue.
114+
func (queue *uniqueSourceFileQueue) Pop() *sourceFile {
115+
old := *queue
116+
x := old[0]
117+
*queue = old[1:]
118+
return x
119+
}
120+
121+
// Empty returns true if the queue is Empty.
122+
func (queue uniqueSourceFileQueue) Empty() bool {
123+
return len(queue) == 0
124+
}

0 commit comments

Comments
 (0)