The speed gate's chain and running recalculations allocated a closure for each formula and each operand to infer their format; the sheet keeps its paged test once per recalculation and InferFormat recurses directly.
- commit
- 92d47e3919d2e7825ae5cf62866acc784c439761
- parent
- e49ca3c3561c7992a9dbbdc480bed29a67c58e46
- author
- Dami <dami.etoile@gmail.com>
- kind
- refactor risk score 1.2 of 3, Jev's estimate
| M | internal/ | 9 | ++++----- |
| M | internal/ | 6 | +++--- |
| M | internal/ | 3 | +++ |
@@ -38,7 +38,6 @@ func IsVolatile(n Node) bool {
3838 // reports whether a sheet is a linked source's tab, whose counts show as3939 // whole numbers with thousands separators.4040 func InferFormat(n Node, at func(string, Addr) Format, paged func(string) bool) Format {41- infer := func(n Node) Format { return InferFormat(n, at, paged) }4241 switch n := n.(type) {4342 case formula.Ref:4443 return at(n.Sheet, n.Addr)@@ -46,10 +45,10 @@ func InferFormat(n Node, at func(string, Addr) Format, paged func(string) bool)
4645 return at(n.Sheet, n.Rect.From)4746 case formula.Unary:4847 if n.Op == "-" || n.Op == "+" {49- return infer(n.X)48+ return InferFormat(n.X, at, paged)5049 }5150 case formula.Binary:52- l, r := infer(n.L), infer(n.R)51+ l, r := InferFormat(n.L, at, paged), InferFormat(n.R, at, paged)5352 switch n.Op {5453 case "+", "-":5554 if n.Op == "-" && l.Kind.IsTime() && r.Kind.IsTime() {@@ -68,10 +67,10 @@ func InferFormat(n Node, at func(string, Addr) Format, paged func(string) bool)
6867 return wholeNumber6968 }7069 if f.format != nil {71- return f.format(n.Args, infer)70+ return f.format(n.Args, func(n Node) Format { return InferFormat(n, at, paged) })7271 }7372 case formula.Array:74- return infer(n.Rows[0][0])73+ return InferFormat(n.Rows[0][0], at, paged)7574 }7675 return Format{}7776 }@@ -61,7 +61,7 @@ func (w *Workbook) evaluate() {
6161 s.version++6262 s.hidden.valid = false // values may have changed what the filter hides6363 s.calcGet = w.recalcReader(s, e, memo)64- s.calcFmt = w.formatFrom(s)64+ s.calcFmt, s.calcPaged = w.formatFrom(s), s.calcGet.Paged6565 }6666 for _, s := range w.sheets {6767 for !e.sweep(s) {@@ -71,7 +71,7 @@ func (w *Workbook) evaluate() {
7171 for _, s := range w.sheets {7272 s.calcGet.read, s.calcGet.memo = nil, nil7373 s.calcGet.lib.Forget()74- s.calc, s.calcGet, s.calcFmt = nil, nil, nil74+ s.calc, s.calcGet, s.calcFmt, s.calcPaged = nil, nil, nil, nil7575 }7676 }7777 @@ -143,7 +143,7 @@ func (e *evaluator) formula(s *Sheet, a Addr, c *Cell) {
143143 w.noteSpill(s, a, c, arr)144144 }145145 w.evaluating = outer146- c.auto = functions.InferFormat(expr, s.calcFmt, s.calcGet.Paged)146+ c.auto = functions.InferFormat(expr, s.calcFmt, s.calcPaged)147147 w.depth--148148 }149149 @@ -99,6 +99,9 @@ type Sheet struct {
9999 calc map[Addr]int100100 calcGet *reader101101 calcFmt func(string, Addr) Format102+ // calcPaged reports whether a sheet is a linked source's tab, whose103+ // counts show as whole numbers.104+ calcPaged func(string) bool102105 // recalcs is calcGet kept between recalculations, so the buffers the103106 // function library reads ranges through are made once.104107 recalcs *reader