adjust implements list size adjustment logic, given a delta in size, and an index to adjust at
(l MutableList, at, delta int)
| 149 | // adjust implements list size adjustment logic, given a delta in size, and an |
| 150 | // index to adjust at |
| 151 | func adjust(l MutableList, at, delta int) { |
| 152 | if delta == 0 { |
| 153 | return |
| 154 | } |
| 155 | oldLen := l.Length() |
| 156 | newLen := oldLen + delta |
| 157 | if delta > 0 { |
| 158 | l.Resize(newLen) |
| 159 | } |
| 160 | copyStart := at - delta |
| 161 | copyTo := at |
| 162 | if copyStart < 0 { |
| 163 | copyTo -= copyStart |
| 164 | copyStart = 0 |
| 165 | } |
| 166 | l.Copy(copyTo, copyStart, newLen-copyTo) |
| 167 | if delta < 0 { |
| 168 | l.Resize(newLen) |
| 169 | } |
| 170 | } |