Refactoring: simplification. #70

This commit is contained in:
Andrey Smirnov
2014-07-10 00:43:42 +04:00
parent bdbb5acb11
commit 9af10bc422
+3 -9
View File
@@ -334,13 +334,11 @@ func (l *PackageList) PrepareIndex() {
} }
// Search searches package index for specified package // Search searches package index for specified package
func (l *PackageList) Search(dep Dependency, allMatches bool) []*Package { func (l *PackageList) Search(dep Dependency, allMatches bool) (searchResults []*Package) {
if !l.indexed { if !l.indexed {
panic("list not indexed, can't search") panic("list not indexed, can't search")
} }
searchResults := []*Package{}
if dep.Relation == VersionDontCare { if dep.Relation == VersionDontCare {
for _, p := range l.providesIndex[dep.Pkg] { for _, p := range l.providesIndex[dep.Pkg] {
if p.MatchesArchitecture(dep.Architecture) { if p.MatchesArchitecture(dep.Architecture) {
@@ -352,7 +350,7 @@ func (l *PackageList) Search(dep Dependency, allMatches bool) []*Package {
} }
} }
if len(searchResults) != 0 { if len(searchResults) != 0 {
return searchResults return
} }
} }
@@ -371,11 +369,7 @@ func (l *PackageList) Search(dep Dependency, allMatches bool) []*Package {
i++ i++
} }
if len(searchResults) != 0 { return
return searchResults
}
return nil
} }
// Filter filters package index by specified queries (ORed together), possibly pulling dependencies // Filter filters package index by specified queries (ORed together), possibly pulling dependencies