Sfoglia il codice sorgente

Use alpm's built in searching for -Ss

This allows us to support the usage option in pacman.conf
This also speeds up the searching
morganamilo 6 anni fa
parent
commit
3180c66f39
1 ha cambiato i file con 13 aggiunte e 36 eliminazioni
  1. 13 36
      query.go

+ 13 - 36
query.go

@@ -260,46 +260,23 @@ func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) {
 		return
 	}
 
-	// BottomUp functions
-	initL := func(len int) int {
-		if config.SortMode == TopDown {
-			return 0
-		}
-		return len - 1
-	}
-	compL := func(len int, i int) bool {
-		if config.SortMode == TopDown {
-			return i < len
-		}
-		return i > -1
-	}
-	finalL := func(i int) int {
-		if config.SortMode == TopDown {
-			return i + 1
+	dbList.ForEach(func(db alpm.Db) error {
+		if len(pkgInputN) == 0 {
+			pkgs := db.PkgCache()
+			s = append(s, pkgs.Slice()...)
+		} else {
+			pkgs := db.Search(pkgInputN)
+			s = append(s, pkgs.Slice()...)
 		}
-		return i - 1
-	}
-
-	dbS := dbList.Slice()
-	lenDbs := len(dbS)
-	for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) {
-		pkgS := dbS[f].PkgCache().Slice()
-		lenPkgs := len(pkgS)
-		for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
-			match := true
-			for _, pkgN := range pkgInputN {
-				if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) {
-					match = false
-					break
-				}
-			}
+		return nil
+	})
 
-			if match {
-				n++
-				s = append(s, pkgS[i])
-			}
+	if config.SortMode == BottomUp {
+		for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
+			s[i], s[j] = s[j], s[i]
 		}
 	}
+
 	return
 }