Skip to content

Commit 8fba85a

Browse files
committed
Added SourceFile.Equals() and converted all SourceFile object to pointers
1 parent c836534 commit 8fba85a

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
@@ -307,7 +307,7 @@ func (cache *includeCache) WriteToFile() error {
307307
return nil
308308
}
309309

310-
func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
310+
func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile *SourceFile) error {
311311
sourcePath := sourceFile.SourcePath()
312312
targetFilePath := paths.NullPath()
313313
depPath := sourceFile.DepfilePath()
@@ -440,23 +440,23 @@ type SourceFile struct {
440440
RelativePath *paths.Path
441441
}
442442

443-
func (f SourceFile) String() string {
443+
func (f *SourceFile) String() string {
444444
return fmt.Sprintf("Root: %s - Path: %s - BuildPath: %s",
445445
f.SourceRoot, f.RelativePath, f.BuildRoot)
446446
}
447447

448448
// MakeSourceFile creates a SourceFile containing the given source file path
449449
// within the given sourceRoot. If srcPath is absolute it is transformed to
450450
// relative to sourceRoot.
451-
func MakeSourceFile(sourceRoot, buildRoot, srcPath *paths.Path) (SourceFile, error) {
451+
func MakeSourceFile(sourceRoot, buildRoot, srcPath *paths.Path) (*SourceFile, error) {
452452
if srcPath.IsAbs() {
453453
if relPath, err := sourceRoot.RelTo(srcPath); err == nil {
454454
srcPath = relPath
455455
} else {
456-
return SourceFile{}, err
456+
return nil, err
457457
}
458458
}
459-
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
459+
return &SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
460460
}
461461

462462
// SourcePath returns the path to the source file
@@ -474,22 +474,30 @@ func (f *SourceFile) DepfilePath() *paths.Path {
474474
return f.BuildRoot.Join(f.RelativePath.String() + ".d")
475475
}
476476

477+
// Equals return true if the SourceFile equals to the SourceFile
478+
// passed as parameter
479+
func (f *SourceFile) Equals(other *SourceFile) bool {
480+
return f.BuildRoot.EqualsTo(other.BuildRoot) &&
481+
f.SourceRoot.EqualsTo(other.SourceRoot) &&
482+
f.RelativePath.EqualsTo(other.RelativePath)
483+
}
484+
477485
type UniqueSourceFileQueue struct {
478-
queue []SourceFile
486+
queue []*SourceFile
479487
curr int
480488
}
481489

482490
func (q *UniqueSourceFileQueue) Len() int {
483491
return len(q.queue) - q.curr
484492
}
485493

486-
func (q *UniqueSourceFileQueue) Push(value SourceFile) {
494+
func (q *UniqueSourceFileQueue) Push(value *SourceFile) {
487495
if !q.Contains(value) {
488496
q.queue = append(q.queue, value)
489497
}
490498
}
491499

492-
func (q *UniqueSourceFileQueue) Pop() SourceFile {
500+
func (q *UniqueSourceFileQueue) Pop() *SourceFile {
493501
res := q.queue[q.curr]
494502
q.curr++
495503
return res
@@ -499,11 +507,9 @@ func (q *UniqueSourceFileQueue) Empty() bool {
499507
return q.Len() == 0
500508
}
501509

502-
func (q *UniqueSourceFileQueue) Contains(target SourceFile) bool {
510+
func (q *UniqueSourceFileQueue) Contains(target *SourceFile) bool {
503511
for _, elem := range q.queue {
504-
if elem.BuildRoot.EqualsTo(target.BuildRoot) &&
505-
elem.SourceRoot.EqualsTo(target.SourceRoot) &&
506-
elem.RelativePath.EqualsTo(target.RelativePath) {
512+
if elem.Equals(target) {
507513
return true
508514
}
509515
}

0 commit comments

Comments
 (0)