Name a fresh hold set's two spellings, eager and lazy

This commit is contained in:
2026-09-22 21:35:22 +02:00
committed by Lillem4n
parent 19274ccb2b
commit d0d9df5220
5 changed files with 13 additions and 13 deletions
+8 -4
View File
@@ -19,15 +19,19 @@ type renderScope struct {
row int row int
} }
// newHoldSet makes the unnamed group's maps where the set is declared, keeping them on that frame's // eagerHoldSet makes the unnamed group's maps where the set is declared, keeping them on that frame's
// stack for a render that reads through them; a zero holdSet makes them on its first read instead. // stack for a render that reads through them; lazyHoldSet makes them on its first read instead.
func newHoldSet(s *session) holdSet { func eagerHoldSet(s *session) holdSet {
return holdSet{unnamed: hold{variant: map[string]node{}, value: map[string]draw{}, s: s}} return holdSet{unnamed: hold{variant: map[string]node{}, value: map[string]draw{}, s: s}}
} }
func lazyHoldSet(s *session) holdSet {
return holdSet{unnamed: hold{s: s}}
}
// renderOnce renders n as one render, over a hold set of its own. // renderOnce renders n as one render, over a hold set of its own.
func renderOnce(s *session, n node) string { func renderOnce(s *session, n node) string {
set := holdSet{unnamed: hold{s: s}} set := lazyHoldSet(s)
return render(s, n, renderScope{set: &set}) return render(s, n, renderScope{set: &set})
} }
+2 -2
View File
@@ -130,7 +130,7 @@ func (f *Generator) FakeRecord(path string) (*Record, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("fejkdata: %s: %w", path, err) return nil, fmt.Errorf("fejkdata: %s: %w", path, err)
} }
set := newHoldSet(f.rand) set := eagerHoldSet(f.rand)
sc := renderScope{set: &set} sc := renderScope{set: &set}
if t, isTable := n.(*table); isTable { if t, isTable := n.(*table); isTable {
if n, err = tableRecord(f.rand, t, tail, sc); err != nil { if n, err = tableRecord(f.rand, t, tail, sc); err != nil {
@@ -204,7 +204,7 @@ type RecordTemplate struct {
func (t *RecordTemplate) Fake() *Record { func (t *RecordTemplate) Fake() *Record {
t.g.mu.Lock() t.g.mu.Lock()
defer t.g.mu.Unlock() defer t.g.mu.Unlock()
set := newHoldSet(t.g.rand) set := eagerHoldSet(t.g.rand)
return renderRecord(t.g.rand, t.t, t.columns, renderScope{set: &set}) return renderRecord(t.g.rand, t.t, t.columns, renderScope{set: &set})
} }
+2 -2
View File
@@ -23,7 +23,7 @@ func (f *Generator) Fake(path string) (string, error) {
if err != nil { if err != nil {
return "", fmt.Errorf("fejkdata: %w", err) return "", fmt.Errorf("fejkdata: %w", err)
} }
f.set = holdSet{unnamed: hold{s: f.rand}} f.set = lazyHoldSet(f.rand)
sc := renderScope{set: &f.set} sc := renderScope{set: &f.set}
f.root.children = f.categories f.root.children = f.categories
n, err := descend(f.rand, &f.root, segments, sc) n, err := descend(f.rand, &f.root, segments, sc)
@@ -101,7 +101,7 @@ func render(s *session, n node, sc renderScope) string {
// //
//go:noinline //go:noinline
func expandAnew(s *session, t *template) string { func expandAnew(s *session, t *template) string {
set := holdSet{unnamed: hold{s: s}} set := lazyHoldSet(s)
return expand(s, t, renderScope{set: &set}) return expand(s, t, renderScope{set: &set})
} }
+1 -1
View File
@@ -349,7 +349,7 @@ func (p *valueProof) checkField(label string, ft reflect.Type, column node) erro
// fill draws the record into v's tagged fields, then each nested struct as a record of its own. // fill draws the record into v's tagged fields, then each nested struct as a record of its own.
func (s *structShape) fill(sess *session, v reflect.Value) { func (s *structShape) fill(sess *session, v reflect.Value) {
if s.record != nil { if s.record != nil {
set := newHoldSet(sess) set := eagerHoldSet(sess)
for i, c := range renderRecord(sess, s.record, s.columns, renderScope{set: &set}).columns { for i, c := range renderRecord(sess, s.record, s.columns, renderScope{set: &set}).columns {
setColumn(fieldAt(v, s.fields[i]), c) setColumn(fieldAt(v, s.fields[i]), c)
} }
-4
View File
@@ -22,10 +22,6 @@ load-time fence and render-time machinery, so no file name said whether a unit r
This round, in order: This round, in order:
- Spell one fresh hold set one way: `newHoldSet` exists, and `render.go` and
`holdset.go` hand-roll `holdSet{unnamed: hold{s: s}}` at three sites; name the
lazy-map variant if the difference is deliberate, and put the hold set in one file:
`holdset.go` holds 57 lines after the split, and `render.go` two of the three sites.
- Run the package doc's Go example under test, as `readme_test.go` runs the README's - Run the package doc's Go example under test, as `readme_test.go` runs the README's
JSON blocks: `doc.go` and the README both print `Järvedsvägen 43\n891 77 Järved` JSON blocks: `doc.go` and the README both print `Järvedsvägen 43\n891 77 Järved`
for seed 42, and nothing renders either, so a draw that moves leaves both false. for seed 42, and nothing renders either, so a draw that moves leaves both false.