Name a fresh hold set's two spellings, eager and lazy
This commit is contained in:
+8
-4
@@ -19,15 +19,19 @@ type renderScope struct {
|
||||
row int
|
||||
}
|
||||
|
||||
// newHoldSet 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.
|
||||
func newHoldSet(s *session) holdSet {
|
||||
// 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; lazyHoldSet makes them on its first read instead.
|
||||
func eagerHoldSet(s *session) holdSet {
|
||||
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.
|
||||
func renderOnce(s *session, n node) string {
|
||||
set := holdSet{unnamed: hold{s: s}}
|
||||
set := lazyHoldSet(s)
|
||||
return render(s, n, renderScope{set: &set})
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ func (f *Generator) FakeRecord(path string) (*Record, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fejkdata: %s: %w", path, err)
|
||||
}
|
||||
set := newHoldSet(f.rand)
|
||||
set := eagerHoldSet(f.rand)
|
||||
sc := renderScope{set: &set}
|
||||
if t, isTable := n.(*table); isTable {
|
||||
if n, err = tableRecord(f.rand, t, tail, sc); err != nil {
|
||||
@@ -204,7 +204,7 @@ type RecordTemplate struct {
|
||||
func (t *RecordTemplate) Fake() *Record {
|
||||
t.g.mu.Lock()
|
||||
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})
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ func (f *Generator) Fake(path string) (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("fejkdata: %w", err)
|
||||
}
|
||||
f.set = holdSet{unnamed: hold{s: f.rand}}
|
||||
f.set = lazyHoldSet(f.rand)
|
||||
sc := renderScope{set: &f.set}
|
||||
f.root.children = f.categories
|
||||
n, err := descend(f.rand, &f.root, segments, sc)
|
||||
@@ -101,7 +101,7 @@ func render(s *session, n node, sc renderScope) string {
|
||||
//
|
||||
//go:noinline
|
||||
func expandAnew(s *session, t *template) string {
|
||||
set := holdSet{unnamed: hold{s: s}}
|
||||
set := lazyHoldSet(s)
|
||||
return expand(s, t, renderScope{set: &set})
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
func (s *structShape) fill(sess *session, v reflect.Value) {
|
||||
if s.record != nil {
|
||||
set := newHoldSet(sess)
|
||||
set := eagerHoldSet(sess)
|
||||
for i, c := range renderRecord(sess, s.record, s.columns, renderScope{set: &set}).columns {
|
||||
setColumn(fieldAt(v, s.fields[i]), c)
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ load-time fence and render-time machinery, so no file name said whether a unit r
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user