(list, index, value)
| 457 | } |
| 458 | |
| 459 | function updateList(list, index, value) { |
| 460 | index = wrapIndex(list, index); |
| 461 | |
| 462 | if (index !== index) { |
| 463 | return list; |
| 464 | } |
| 465 | |
| 466 | if (index >= list.size || index < 0) { |
| 467 | return list.withMutations((list) => { |
| 468 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here |
| 469 | index < 0 |
| 470 | ? setListBounds(list, index).set(0, value) |
| 471 | : setListBounds(list, 0, index + 1).set(index, value); |
| 472 | }); |
| 473 | } |
| 474 | |
| 475 | index += list._origin; |
| 476 | |
| 477 | let newTail = list._tail; |
| 478 | let newRoot = list._root; |
| 479 | const didAlter = MakeRef(); |
| 480 | if (index >= getTailOffset(list._capacity)) { |
| 481 | newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter); |
| 482 | } else { |
| 483 | newRoot = updateVNode( |
| 484 | newRoot, |
| 485 | list.__ownerID, |
| 486 | list._level, |
| 487 | index, |
| 488 | value, |
| 489 | didAlter |
| 490 | ); |
| 491 | } |
| 492 | |
| 493 | if (!didAlter.value) { |
| 494 | return list; |
| 495 | } |
| 496 | |
| 497 | if (list.__ownerID) { |
| 498 | list._root = newRoot; |
| 499 | list._tail = newTail; |
| 500 | list.__hash = undefined; |
| 501 | list.__altered = true; |
| 502 | return list; |
| 503 | } |
| 504 | return makeList(list._origin, list._capacity, list._level, newRoot, newTail); |
| 505 | } |
| 506 | |
| 507 | function updateVNode(node, ownerID, level, index, value, didAlter) { |
| 508 | const idx = (index >>> level) & MASK; |
no test coverage detected