put and EraseRange take a cell's format, style and note from the store rather than a view of the whole cell, and a deleted sheet's cells count toward the undo budget at what the store holds for them (a slot each, plus rich cells and strings), not at a Cell each.
- commit
- ad611c4e4c1f3ee17e61c436356112a9f786f60b
- parent
- e43841fa81e8f575bc07e58c702365d02a820911
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 2 | +- |
| M | internal/ | 2 | +- |
| M | internal/ | 11 | ++++------- |
| M | internal/ | 21 | +++++++++++++++++++++ |
@@ -73,7 +73,7 @@ func (w *Workbook) deletedSize(st *step) int64 {
7373 var n int647474 for _, s := range st.sheets.order {7575 if !slices.Contains(w.sheets, s) {76- n += int64(s.Len()) * (entryBytes + cellBytes)76+ n += s.cells.size()7777 }7878 }7979 return n@@ -109,7 +109,7 @@ func TestUndoBytesCountDeletedSheet(t *testing.T) {
109109 if err := w.DeleteSheet(data); err != nil {110110 t.Fatal(err)111111 }112- if got := w.HistoryBytes(); got < 500*cellBytes {112+ if got := w.HistoryBytes(); got < 500*slotBytes {113113 t.Errorf("deleting a 500-cell sheet is estimated at %d bytes", got)114114 }115115 }@@ -236,12 +236,8 @@ func (s *Sheet) Set(a Addr, input string) error {
236236 // put stores an entry without recalculating, keeping the cell's237237 // formatting.238238 func (s *Sheet) put(a Addr, input string) error {239- var f Format240- var st Style241- var note string242- if old := s.cells.get(a); old != nil {243- f, st, note = old.Format, old.Style, old.Note244- }239+ f, st, _ := s.cells.look(a)240+ note := s.Note(a)245241 if f.IsZero() && !st.own && s.inherited(a).Format.Kind == FmtText {246242 f = Format{Kind: FmtText} // typed into a plain text column: text247243 }@@ -380,7 +376,8 @@ func (s *Sheet) EraseRange(r Rect) {
380376 s.change("clear "+r.String(), r, func() {381377 for _, a := range s.cellsIn(r) {382378 if s.cells.filledAt(a) {383- s.place(a, s.cells.get(a).leftover())379+ f, st, _ := s.cells.look(a)380+ s.place(a, formattingOnly(f, st).withNote(s.Note(a)))384381 }385382 }386383 })@@ -244,6 +244,27 @@ func (st *cellStore) releaseSlot(sl slot) {
244244 }245245 }246246 247+// Estimated heap of the store's parts, for the undo history's budget248+// (historysize.go): a slot with its share of the blocks and indexes, as249+// BenchmarkMemory measures it, and a string's entry in the table.250+const (251+ slotBytes = 20252+ strBytes = 64253+)254+255+// size estimates the heap the cells hold: a slot each, and the rich256+// cells and strings on top.257+func (st *cellStore) size() int64 {258+ n := int64(st.len()) * slotBytes259+ for _, rc := range st.rich {260+ n += cellSize(rc.c)261+ }262+ for _, s := range st.strs.strs {263+ n += strBytes + int64(len(s))264+ }265+ return n266+}267+247268 // richCell is a rich cell and where it is.248269 type richCell struct {249270 c *Cell