Skip to content

Commit 3bdd8b2

Browse files
committed
refactor: avoid double scanning of the sketch if profile is active
1 parent 8a3ce8b commit 3bdd8b2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

commands/instances.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
155155

156156
// Try to extract profile if specified
157157
var profile *sketch.Profile
158+
var profileSketchFullPath *paths.Path
158159
if req.GetProfile() != "" {
159160
sk, err := sketch.New(paths.New(req.GetSketchPath()))
160161
if err != nil {
161162
return &cmderrors.InvalidArgumentError{Cause: err}
162163
}
164+
profileSketchFullPath = sk.FullPath
163165
p, err := sk.GetProfile(req.GetProfile())
164166
if err != nil {
165167
return err
@@ -371,11 +373,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
371373
if libraryRef.InstallDir != nil {
372374
libDir := libraryRef.InstallDir
373375
if !libDir.IsAbs() {
374-
sk, err := sketch.New(paths.New(req.GetSketchPath()))
375-
if err != nil {
376-
return &cmderrors.InvalidArgumentError{Cause: err}
377-
}
378-
libDir = sk.FullPath.JoinPath(libraryRef.InstallDir)
376+
libDir = profileSketchFullPath.JoinPath(libraryRef.InstallDir)
379377
}
380378
if !libDir.IsDir() {
381379
return &cmderrors.InvalidArgumentError{

0 commit comments

Comments
 (0)