Skip to content

Commit 0f88170

Browse files
committed
Added SourceFile.Equals() and converted all SourceFile object to pointers
1 parent 68c66b1 commit 0f88170

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

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

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

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

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

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

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

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

493-
func (q *UniqueSourceFileQueue) Pop() SourceFile {
501+
func (q *UniqueSourceFileQueue) Pop() *SourceFile {
494502
res := q.queue[q.curr]
495503
q.curr++
496504
return res
@@ -500,11 +508,9 @@ func (q *UniqueSourceFileQueue) Empty() bool {
500508
return q.Len() == 0
501509
}
502510

503-
func (q *UniqueSourceFileQueue) Contains(target SourceFile) bool {
511+
func (q *UniqueSourceFileQueue) Contains(target *SourceFile) bool {
504512
for _, elem := range q.queue {
505-
if elem.BuildRoot.EqualsTo(target.BuildRoot) &&
506-
elem.SourceRoot.EqualsTo(target.SourceRoot) &&
507-
elem.RelativePath.EqualsTo(target.RelativePath) {
513+
if elem.Equals(target) {
508514
return true
509515
}
510516
}

0 commit comments

Comments
 (0)