Skip to content

Commit c388af5

Browse files
committed
Added SourceFile.Equals() and converted all SourceFile object to pointers
1 parent 06c66e7 commit c388af5

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

legacy/builder/container_find_includes.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (cache *includeCache) WriteToFile() error {
318318
return nil
319319
}
320320

321-
func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
321+
func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile *SourceFile) error {
322322
sourcePath := sourceFile.SourcePath()
323323
targetFilePath := paths.NullPath()
324324
depPath := sourceFile.DepfilePath()
@@ -459,23 +459,23 @@ type SourceFile struct {
459459
RelativePath *paths.Path
460460
}
461461

462-
func (f SourceFile) String() string {
462+
func (f *SourceFile) String() string {
463463
return fmt.Sprintf("Root: %s - Path: %s - BuildPath: %s",
464464
f.SourceRoot, f.RelativePath, f.BuildRoot)
465465
}
466466

467467
// MakeSourceFile creates a SourceFile containing the given source file path
468468
// within the given sourceRoot. If srcPath is absolute it is transformed to
469469
// relative to sourceRoot.
470-
func MakeSourceFile(sourceRoot, buildRoot, srcPath *paths.Path) (SourceFile, error) {
470+
func MakeSourceFile(sourceRoot, buildRoot, srcPath *paths.Path) (*SourceFile, error) {
471471
if srcPath.IsAbs() {
472472
if relPath, err := sourceRoot.RelTo(srcPath); err == nil {
473473
srcPath = relPath
474474
} else {
475-
return SourceFile{}, err
475+
return nil, err
476476
}
477477
}
478-
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
478+
return &SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
479479
}
480480

481481
// SourcePath returns the path to the source file
@@ -493,22 +493,30 @@ func (f *SourceFile) DepfilePath() *paths.Path {
493493
return f.BuildRoot.Join(f.RelativePath.String() + ".d")
494494
}
495495

496+
// Equals return true if the SourceFile equals to the SourceFile
497+
// passed as parameter
498+
func (f *SourceFile) Equals(other *SourceFile) bool {
499+
return f.BuildRoot.EqualsTo(other.BuildRoot) &&
500+
f.SourceRoot.EqualsTo(other.SourceRoot) &&
501+
f.RelativePath.EqualsTo(other.RelativePath)
502+
}
503+
496504
type UniqueSourceFileQueue struct {
497-
queue []SourceFile
505+
queue []*SourceFile
498506
curr int
499507
}
500508

501509
func (q *UniqueSourceFileQueue) Len() int {
502510
return len(q.queue) - q.curr
503511
}
504512

505-
func (q *UniqueSourceFileQueue) Push(value SourceFile) {
513+
func (q *UniqueSourceFileQueue) Push(value *SourceFile) {
506514
if !q.Contains(value) {
507515
q.queue = append(q.queue, value)
508516
}
509517
}
510518

511-
func (q *UniqueSourceFileQueue) Pop() SourceFile {
519+
func (q *UniqueSourceFileQueue) Pop() *SourceFile {
512520
res := q.queue[q.curr]
513521
q.curr++
514522
return res
@@ -518,11 +526,9 @@ func (q *UniqueSourceFileQueue) Empty() bool {
518526
return q.Len() == 0
519527
}
520528

521-
func (q *UniqueSourceFileQueue) Contains(target SourceFile) bool {
529+
func (q *UniqueSourceFileQueue) Contains(target *SourceFile) bool {
522530
for _, elem := range q.queue {
523-
if elem.BuildRoot.EqualsTo(target.BuildRoot) &&
524-
elem.SourceRoot.EqualsTo(target.SourceRoot) &&
525-
elem.RelativePath.EqualsTo(target.RelativePath) {
531+
if elem.Equals(target) {
526532
return true
527533
}
528534
}

0 commit comments

Comments
 (0)