|
Boost : |
From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-01-29 00:13:39
From: Dave Abrahams <abrahams_at_[hidden]>
> > 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 ;)
Not only that topic, thank God.
> 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 ;)
This looks much better, and may indeed be much faster. I'll leave it
to Mark to tweak his code to get this expansion.
I still count 6 loads/stores versus 12 loads/stores.
> ------------------------------------------------------------------------
> Want to send money instantly to anyone, anywhere, anytime?
> You can today at X.com - and we'll give you $20 to try it! Sign
> up today at X.com. It's quick, free, & there's no obligation!
> http://click.egroups.com/1/332/1/_/9351/_/949122487/
>
> eGroups.com Home: http://www.egroups.com/group/boost/
> http://www.egroups.com - Simplifying group communications
>
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk