instantiated: rename Drv method to Instantiated

This avoids confusion with actual derivation structs.
This commit is contained in:
Ophestra 2025-07-14 22:34:44 +09:00
parent 1c968c1e36
commit b79eeea0db
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 5 additions and 5 deletions

View File

@ -72,8 +72,8 @@ func NewInstantiatedDecoder(r io.Reader) *InstantiatedDecoder {
return &InstantiatedDecoder{scanner: bufio.NewScanner(r)} return &InstantiatedDecoder{scanner: bufio.NewScanner(r)}
} }
// Drv returns a non-reusable iterator over instantiated derivations collected from [io.Reader]. // Instantiated returns a non-reusable iterator over instantiated derivations collected from [io.Reader].
func (d *InstantiatedDecoder) Drv() iter.Seq[string] { func (d *InstantiatedDecoder) Instantiated() iter.Seq[string] {
return func(yield func(string) bool) { return func(yield func(string) bool) {
for d.scanner.Scan() { for d.scanner.Scan() {
v := d.scanner.Text() v := d.scanner.Text()
@ -114,7 +114,7 @@ func (d *InstantiatedDecoder) Drv() iter.Seq[string] {
// Decode collects and deduplicates derivations emitted by [InstantiatedDecoder]. // Decode collects and deduplicates derivations emitted by [InstantiatedDecoder].
func (d *InstantiatedDecoder) Decode() ([]string, error) { func (d *InstantiatedDecoder) Decode() ([]string, error) {
instantiated := make([]string, 0, instantiatedInitialCap) instantiated := make([]string, 0, instantiatedInitialCap)
for drv := range d.Drv() { for drv := range d.Instantiated() {
if len(instantiated) == cap(instantiated) { if len(instantiated) == cap(instantiated) {
// grow the buffer exponentially to minimise copies // grow the buffer exponentially to minimise copies
instantiated = slices.Grow(instantiated, cap(instantiated)<<1) instantiated = slices.Grow(instantiated, cap(instantiated)<<1)

View File

@ -74,7 +74,7 @@ func TestDecodeInstantiated(t *testing.T) {
decoder := nixbuild.NewInstantiatedDecoder(strings.NewReader(segmentPrefix + segmentBody + segmentSuffix)) decoder := nixbuild.NewInstantiatedDecoder(strings.NewReader(segmentPrefix + segmentBody + segmentSuffix))
counter := 3 counter := 3
got := make([]string, 0, counter) got := make([]string, 0, counter)
for drv := range decoder.Drv() { for drv := range decoder.Instantiated() {
got = append(got, drv) got = append(got, drv)
counter-- counter--
if counter == 0 { if counter == 0 {
@ -83,7 +83,7 @@ func TestDecodeInstantiated(t *testing.T) {
} }
if !slices.Equal(got, want) { if !slices.Equal(got, want) {
t.Errorf("Drv: %#v, want %#v", got, want) t.Errorf("Instantiated: %#v, want %#v", got, want)
} }
}) })