Skip to content

Commit 56cb492

Browse files
committed
In ResolveLibrary the existence-map markImportedLibrary is useless
It may have had its purposes in the past, but now it's basically useless since it's only used to cycle in `for... range` loops. Signed-off-by: Cristian Maglie <[email protected]>
1 parent 31156ba commit 56cb492

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/arduino.cc/builder/resolve_library.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ func ResolveLibrary(ctx *types.Context, header string) *types.Library {
4444
libraryResolutionResults := ctx.LibrariesResolutionResults
4545
importedLibraries := ctx.ImportedLibraries
4646

47-
markImportedLibrary := make(map[*types.Library]bool)
48-
for _, library := range importedLibraries {
49-
markImportedLibrary[library] = true
50-
}
51-
5247
libraries := append([]*types.Library{}, headerToLibraries[header]...)
5348

5449
if libraries == nil || len(libraries) == 0 {
5550
return nil
5651
}
5752

58-
if markImportedLibraryContainsOneOfCandidates(markImportedLibrary, libraries) {
53+
if importedLibraryContainsOneOfCandidates(importedLibraries, libraries) {
5954
return nil
6055
}
6156

@@ -87,7 +82,7 @@ func ResolveLibrary(ctx *types.Context, header string) *types.Library {
8782
library = libraries[0]
8883
}
8984

90-
library = useAlreadyImportedLibraryWithSameNameIfExists(library, markImportedLibrary)
85+
library = useAlreadyImportedLibraryWithSameNameIfExists(library, importedLibraries)
9186

9287
libraryResolutionResults[header] = types.LibraryResolutionResult{Library: library, NotUsedLibraries: filterOutLibraryFrom(libraries, library)}
9388

@@ -101,19 +96,19 @@ func reverse(data []*types.Library) {
10196
}
10297
}
10398

104-
func markImportedLibraryContainsOneOfCandidates(markImportedLibrary map[*types.Library]bool, libraries []*types.Library) bool {
105-
for markedLibrary, _ := range markImportedLibrary {
106-
for _, library := range libraries {
107-
if markedLibrary == library {
99+
func importedLibraryContainsOneOfCandidates(imported []*types.Library, candidates []*types.Library) bool {
100+
for _, i := range imported {
101+
for _, j := range candidates {
102+
if i == j {
108103
return true
109104
}
110105
}
111106
}
112107
return false
113108
}
114109

115-
func useAlreadyImportedLibraryWithSameNameIfExists(library *types.Library, markImportedLibrary map[*types.Library]bool) *types.Library {
116-
for lib, _ := range markImportedLibrary {
110+
func useAlreadyImportedLibraryWithSameNameIfExists(library *types.Library, imported []*types.Library) *types.Library {
111+
for _, lib := range imported {
117112
if lib.Name == library.Name {
118113
return lib
119114
}

0 commit comments

Comments
 (0)