Skip to content

Commit d675fc9

Browse files
committed
Factored a method in library.List
1 parent a735ddf commit d675fc9

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

arduino/libraries/librarieslist.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ func (list *List) Add(libs ...*Library) {
4141
}
4242
}
4343

44-
// Remove removes the library from the list
45-
func (list *List) Remove(library *Library) {
44+
// Remove removes the given library from the list
45+
func (list *List) Remove(libraryToRemove *Library) {
46+
j := 0
4647
for i, lib := range *list {
47-
if lib == library {
48-
*list = append((*list)[:i], (*list)[i+1:]...)
49-
return
48+
if lib != libraryToRemove {
49+
if i != j {
50+
(*list)[j] = (*list)[i]
51+
}
52+
j++
5053
}
5154
}
55+
*list = (*list)[:j]
5256
}
5357

5458
// FindByName returns the first library in the list that match

legacy/builder/resolve_library.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@ func ResolveLibrary(ctx *types.Context, header string) *libraries.Library {
5858
}
5959
}
6060

61+
candidates.Remove(selected)
6162
ctx.LibrariesResolutionResults[header] = types.LibraryResolutionResult{
6263
Library: selected,
63-
NotUsedLibraries: filterOutLibraryFrom(candidates, selected),
64+
NotUsedLibraries: candidates,
6465
}
6566

6667
return selected
6768
}
68-
69-
func filterOutLibraryFrom(libs libraries.List, libraryToRemove *libraries.Library) libraries.List {
70-
filteredOutLibraries := []*libraries.Library{}
71-
for _, lib := range libs {
72-
if lib != libraryToRemove {
73-
filteredOutLibraries = append(filteredOutLibraries, lib)
74-
}
75-
}
76-
return filteredOutLibraries
77-
}

0 commit comments

Comments
 (0)