mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	resources/page: Use binary search in Pages.Prev/Next if possible
This is obviously much faster for lager data sets: ```bash name old time/op new time/op delta SearchPage/ByWeight-100-4 267ns ± 4% 272ns ± 5% ~ (p=0.457 n=4+4) SearchPage/ByWeight-5000-4 10.8µs ± 3% 1.2µs ± 2% -88.99% (p=0.029 n=4+4) SearchPage/ByWeight-10000-4 21.1µs ± 1% 1.4µs ±11% -93.28% (p=0.029 n=4+4) ``` See #4500
This commit is contained in:
		@@ -99,7 +99,7 @@ func (wp WeightedPages) Pages() Pages {
 | 
			
		||||
// this weighted page set.
 | 
			
		||||
func (wp WeightedPages) Next(cur Page) Page {
 | 
			
		||||
	for x, c := range wp {
 | 
			
		||||
		if c.Page == cur {
 | 
			
		||||
		if c.Page.Eq(cur) {
 | 
			
		||||
			if x == 0 {
 | 
			
		||||
				return nil
 | 
			
		||||
			}
 | 
			
		||||
@@ -113,7 +113,7 @@ func (wp WeightedPages) Next(cur Page) Page {
 | 
			
		||||
// this weighted page set.
 | 
			
		||||
func (wp WeightedPages) Prev(cur Page) Page {
 | 
			
		||||
	for x, c := range wp {
 | 
			
		||||
		if c.Page == cur {
 | 
			
		||||
		if c.Page.Eq(cur) {
 | 
			
		||||
			if x < len(wp)-1 {
 | 
			
		||||
				return wp[x+1].Page
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user