Repository: dolthub/dolt
File: go/store/datas/pull/pull_chunk_tracker.go (Go)

Code before:
					close(req.ready)
					err = nil
				} else if len(absent) == 0 {
					// We have no more chunks to deliver. If len(absent) == 0 but we had
					// unprocessed stuff, we would have had a |nil| |thisReqCh|. The fact that
					// we accepted the request means we are ready to tell the client that there
					// are no more chunks to fetch.
					req.ok = false
					close(req.ready)
				} else {
					// |absent[0]| is as full a batch as we have.
					req.ok = true
					req.hs, absent = pop(absent)
					unprocessed += len(req.hs)
					close(req.ready)
				}
			case <-ctx.Done():
				return context.Cause(ctx)
			}
		}
	})

	return eg.Wait()
}

// Pop returns the first element of s and the remaining elements of
// s. It copies any suffix to the front of |s| and nils the last
// element of |s| so that memory doesn't leak through |s[1:]| retaining
// s[0].
func pop[T any](s []T) (T, []T) {
	ret := s[0]
	copy(s[:], s[1:])
	var empty T
	s[len(s)-1] = empty
	return ret, s[:len(s)-1]
}

// appendAbsent adds all elements in |toadd| to HashSets at the end of |absent|. It creates new HashSets
// at the end of |absent| if inserting into an existing set would cause its size to exceed |sz|.
//
// As a special case, |appendAbsent| just returns []hash.HashSet{toadd} if |absent| is already empty.
func appendAbsent(absent []hash.HashSet, toadd hash.HashSet, sz int) []hash.HashSet {
	if len(toadd) == 0 {
		return absent
	}
	// Don't bother splitting up toadd to |sz| if it is the first batch.
	if len(absent) == 0 {
		absent = append(absent, toadd)
		return absent
	}
	for h := range toadd {

Review comment (suggestion):
```suggestion
// pop returns the first element of s and the remaining elements of
```

Code after:
					req.err = err
					close(req.ready)
					err = nil
				} else if len(absent) == 0 {
					// We have no more chunks to deliver. If len(absent) == 0 but we had
					// unprocessed stuff, we would have had a |nil| |thisReqCh|. The fact that
					// we accepted the request means we are ready to tell the client that there
					// are no more chunks to fetch.
					req.ok = false
					close(req.ready)
				} else {
					// |absent[0]| is as full a batch as we have.
					req.ok = true
					req.hs, absent = pop(absent)
					unprocessed += len(req.hs)
					close(req.ready)
				}
			case <-ctx.Done():
				return context.Cause(ctx)
			}
		}
	})

	return eg.Wait()
}

// pop returns the first element of s and the remaining elements of
// s. It copies any suffix to the front of |s| and nils the last
// element of |s| so that memory doesn't leak through |s[1:]| retaining
// s[0].
func pop[T any](s []T) (T, []T) {
	ret := s[0]
	copy(s[:], s[1:])
	var empty T
	s[len(s)-1] = empty
	return ret, s[:len(s)-1]
}

// appendAbsent adds all elements in |toadd| to HashSets at the end of |absent|. It creates new HashSets
// at the end of |absent| if inserting into an existing set would cause its size to exceed |sz|.
//
// As a special case, |appendAbsent| just returns []hash.HashSet{toadd} if |absent| is already empty.
func appendAbsent(absent []hash.HashSet, toadd hash.HashSet, sz int) []hash.HashSet {
	if len(toadd) == 0 {
		return absent
	}
	// Don't bother splitting up toadd to |sz| if it is the first batch.
	if len(absent) == 0 {
		absent = append(absent, toadd)
		return absent
	}