Slice returns a Data referencing the subset of the Pool range.
(rng Range)
| 86 | |
| 87 | // Slice returns a Data referencing the subset of the Pool range. |
| 88 | func (m *Pool) Slice(rng Range) Data { |
| 89 | i, c := interval.Intersect(&m.writes, rng.Span()) |
| 90 | if c == 1 { |
| 91 | w := m.writes[i] |
| 92 | if rng == w.dst { |
| 93 | // Exact hit |
| 94 | return w.src |
| 95 | } |
| 96 | if rng.First() >= w.dst.First() && rng.Last() <= w.dst.Last() { |
| 97 | // Subset of a write. |
| 98 | rng.Base -= w.dst.First() |
| 99 | return w.src.Slice(rng) |
| 100 | } |
| 101 | } |
| 102 | writes := make(poolWriteList, c) |
| 103 | copy(writes, m.writes[i:i+c]) |
| 104 | return poolSlice{rng: rng, writes: writes} |
| 105 | } |
| 106 | |
| 107 | // TempSlice returns a slice that is only valid until the next |
| 108 | // Read/Write operation on this pool. |