Skip to content

Commit d63e82b

Browse files
committed
cores:packagemanager Use maps to access board instead of looping
Signed-off-by: Matteo Suppo <matteo.suppo@gmail.com>
1 parent 99cc9b3 commit d63e82b

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

cores/packagemanager/package_manager.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,33 @@ func (pm *PackageManager) FindBoardWithFQBN(fqbn string) (*cores.Board, error) {
125125
if len(fqbnParts) < 3 || len(fqbnParts) > 4 {
126126
return nil, errors.New("incorrect format for fqbn")
127127
}
128+
128129
packageName := fqbnParts[0]
129130
platformArch := fqbnParts[1]
130131
boardID := fqbnParts[2]
131132

132-
// Search for the board
133-
for _, targetPackage := range pm.packages.Packages {
134-
fmt.Println(targetPackage.Name, packageName)
135-
if targetPackage.Name != packageName {
136-
continue
137-
}
138-
for _, targetPlatform := range targetPackage.Platforms {
139-
if targetPlatform.Architecture != platformArch {
140-
continue
141-
}
133+
// Find package
134+
targetPackage := pm.packages.Packages[packageName]
135+
if targetPackage == nil {
136+
return nil, errors.New("unknown package " + packageName)
137+
}
142138

143-
platform := targetPlatform.GetInstalled()
144-
if platform == nil {
145-
return nil, errors.New("platform not installed")
146-
}
147-
for _, board := range platform.Boards {
148-
if board.BoardId == boardID {
149-
return board, nil
150-
}
151-
}
152-
}
139+
// Find platform
140+
platform := targetPackage.Platforms[fqbnParts[1]]
141+
if platform == nil {
142+
return nil, fmt.Errorf("unknown platform %s:%s", packageName, platformArch)
143+
}
144+
platformRelease := platform.GetInstalled()
145+
if platformRelease == nil {
146+
return nil, fmt.Errorf("Platform %s:%s is not installed", packageName, platformArch)
147+
}
148+
149+
// Find board
150+
board := platformRelease.Boards[boardID]
151+
if board == nil {
152+
return nil, errors.New("board not found")
153153
}
154-
return nil, errors.New("board not found")
154+
return board, nil
155155
}
156156

157157
// FIXME add an handler to be invoked on each verbose operation, in order to let commands display results through the formatter

0 commit comments

Comments
 (0)