Skip to content

Commit ed87b28

Browse files
committed
Simplified Profile.RemoveLibrary(...) method.
1 parent 0d8dddb commit ed87b28

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
@@ -136,14 +136,16 @@ func (p *Profile) GetLibrary(libraryName string) (*ProfileLibraryReference, erro
136136
return nil, &cmderrors.LibraryNotFoundError{Library: libraryName}
137137
}
138138

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

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

0 commit comments

Comments
 (0)