RecState returns the state for given index, reconstructing from diffs as needed. Must be called under lock.
(idx int)
| 90 | // RecState returns the state for given index, reconstructing from diffs |
| 91 | // as needed. Must be called under lock. |
| 92 | func (us *Stack) RecState(idx int) []string { |
| 93 | stidx := 0 |
| 94 | var cdt []string |
| 95 | for i := idx; i >= 0; i-- { |
| 96 | r := us.Records[i] |
| 97 | if r.Raw != nil { |
| 98 | stidx = i |
| 99 | cdt = r.Raw |
| 100 | break |
| 101 | } |
| 102 | } |
| 103 | for i := stidx + 1; i <= idx; i++ { |
| 104 | r := us.Records[i] |
| 105 | if r.Patch != nil { |
| 106 | cdt = r.Patch.Apply(cdt) |
| 107 | } |
| 108 | } |
| 109 | return cdt |
| 110 | } |
| 111 | |
| 112 | // Save saves a new action as next action to be undone, with given action |
| 113 | // data and current full state of the system (either of which are optional). |