Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-01-29 00:08:03


> The copy code for the current implementation expands to this:
>
> if (pn != rpn) {
> if (--*pn == 0) { delete px; delete pn; }
> px = rpx;
> ++*(pn = rpn);
> }
>
> The copy code for Mark's implementation expands to this:
>
> lastref = !left && !right;
> if (left || right)
> {
> if (left)
> left->right = right;
> if (right)
> right->left = left;
> right = left = 0;
> }
> if (lastref && ptr)
> delete ptr;
> ptr = pNewLeft->ptr;
> left = pNewLeft;
> right = pNewLeft->right;
> pNewLeft->right = this;
> if (right)
> right->left = this;

Hmm. Never bet against the man with 6+ years' experience in one topic ;)

1. There's no need to check for ptr being 0 before deleting it
2. and of course, using a circular list could cut down the code somewhat:

if (left == this)
    delete ptr;
left->right = right; // unlink
right->left = left;
ptr = pNewLeft->ptr; // adopt
left = pNewLeft; // link
right = pNewLeft->right;
right->left = this;
pNewLeft->right = this;

I notice this has the advantage of containing more straight-line code than
the current implementation does (one branch vs. two). I'd rather see a test
of the circular case ;)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk