Skip to content

Commit 321db83

Browse files
committed
Simplified Profile.RemoveLibrary(...) method.
1 parent ccc8d23 commit 321db83

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

internal/arduino/sketch/profiles.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,16 @@ func (p *Profile) GetLibrary(libraryName string) (*ProfileLibraryReference, erro
137137
return nil, &cmderrors.LibraryNotFoundError{Library: libraryName}
138138
}
139139

140+
// RemoveLibrary removes a library from this profile and returns the removed ProfileLibraryReference.
141+
// If the library is not found, an error is returned.
140142
func (p *Profile) RemoveLibrary(library *ProfileLibraryReference) (*ProfileLibraryReference, error) {
141-
for i, l := range p.Libraries {
142-
if l.Match(library) {
143-
p.Libraries = slices.Delete(p.Libraries, i, i+1)
144-
return l, nil
145-
}
143+
i := slices.IndexFunc(p.Libraries, library.Match)
144+
if i == -1 {
145+
return nil, &cmderrors.LibraryNotFoundError{Library: library.String()}
146146
}
147-
return nil, &cmderrors.LibraryNotFoundError{Library: library.String()}
147+
removedLib := p.Libraries[i]
148+
p.Libraries = slices.Delete(p.Libraries, i, i+1)
149+
return removedLib, nil
148150
}
149151

150152
// ToRpc converts this Profile to an rpc.SketchProfile

0 commit comments

Comments
 (0)