Split stacks at mark
| 575 | |
| 576 | // Split stacks at mark |
| 577 | void split (const const_iterator& mark, Stack<Object, Capacity>& s) |
| 578 | { |
| 579 | fb_assert(&getPool() == &s.getPool()); |
| 580 | fb_assert(!s.stk); |
| 581 | |
| 582 | // if empty stack was merged, there is nothing to do |
| 583 | if (!mark.stk) |
| 584 | { |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | // find entry to Split |
| 589 | Entry **toSplit = &stk; |
| 590 | while (*toSplit != mark.stk) |
| 591 | { |
| 592 | fb_assert(*toSplit); |
| 593 | toSplit = &((*toSplit)->next); |
| 594 | } |
| 595 | |
| 596 | // Determine whether some new elements were added |
| 597 | // to this stack. Depended on this we must |
| 598 | // Split on entries boundary or cut one entry to halfs. |
| 599 | fb_assert((*toSplit)->getCount() >= mark.elem); |
| 600 | if ((*toSplit)->getCount() == mark.elem) |
| 601 | { |
| 602 | s.stk = *toSplit; |
| 603 | *toSplit = 0; |
| 604 | } |
| 605 | else |
| 606 | { |
| 607 | Entry* newEntry = FB_NEW_POOL(getPool()) Entry(0); |
| 608 | (*toSplit)->split(mark.elem, newEntry); |
| 609 | s.stk = *toSplit; |
| 610 | *toSplit = newEntry; |
| 611 | } |
| 612 | |
| 613 | if (s.stk) |
| 614 | { |
| 615 | delete s.stk_cache; |
| 616 | s.stk_cache = 0; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | // clear stacks until mark |
| 621 | void clear (const iterator& mark) |