Skip to content

Commit 4325eda

Browse files
committed
Factored a method in library.List
1 parent 8b631ff commit 4325eda

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

arduino/libraries/librarieslist.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ func (list *List) Add(libs ...*Library) {
3939
}
4040
}
4141

42+
// Remove removes the given library from the list
43+
func (list *List) Remove(libraryToRemove *Library) {
44+
j := 0
45+
for i, lib := range *list {
46+
if lib != libraryToRemove {
47+
if i != j {
48+
(*list)[j] = (*list)[i]
49+
}
50+
j++
51+
}
52+
}
53+
*list = (*list)[:j]
54+
}
55+
4256
// FindByName returns the first library in the list that match
4357
// the specified name or nil if not found
4458
func (list *List) FindByName(name string) *Library {

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)