From a460dafcbc42518b920aad4641103a58ff1ec90e Mon Sep 17 00:00:00 2001 From: Markus Stenberg Date: Fri, 3 May 2024 14:23:08 +0300 Subject: [PATCH] fts: If handed limit, stop filtering beyond that point --- fts.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fts.go b/fts.go index 34a9fcb..a4612df 100644 --- a/fts.go +++ b/fts.go @@ -22,6 +22,12 @@ func filterFTS[T FTSMatchable](s []T, search string, limit int) []T { for _, o := range s { if o.MatchesFTS(search) { filtered = append(filtered, o) + if len(filtered) == limit { + // We won't reuse the filtered result + // anyway, so going beyond limit won't + // be useful + break + } } } return filtered