| 128 | //---------------------------------------------------------------------------- |
| 129 | |
| 130 | void ProcessList::orderList() |
| 131 | { |
| 132 | // ProcessObject tags are initialized to 0, so current tag should never be 0. |
| 133 | if (++mCurrentTag == 0) |
| 134 | mCurrentTag++; |
| 135 | |
| 136 | // Install a temporary head node |
| 137 | ProcessObject list; |
| 138 | list.plLinkBefore(mHead.mProcessLink.next); |
| 139 | mHead.plUnlink(); |
| 140 | |
| 141 | // start out by (bubble) sorting list by GUID |
| 142 | for (ProcessObject * cur = list.mProcessLink.next; cur != &list; cur = cur->mProcessLink.next) |
| 143 | { |
| 144 | if (cur->mOrderGUID == 0) |
| 145 | // special case -- can be no lower, so accept as lowest (this is also |
| 146 | // a common value since it is what non ordered objects have) |
| 147 | continue; |
| 148 | |
| 149 | for (ProcessObject * walk = cur->mProcessLink.next; walk != &list; walk = walk->mProcessLink.next) |
| 150 | { |
| 151 | if (walk->mOrderGUID < cur->mOrderGUID) |
| 152 | { |
| 153 | // swap walk and cur -- need to be careful because walk might be just after cur |
| 154 | // so insert after item before cur and before item after walk |
| 155 | ProcessObject * before = cur->mProcessLink.prev; |
| 156 | ProcessObject * after = walk->mProcessLink.next; |
| 157 | cur->plUnlink(); |
| 158 | walk->plUnlink(); |
| 159 | cur->plLinkBefore(after); |
| 160 | walk->plLinkAfter(before); |
| 161 | ProcessObject * swap = walk; |
| 162 | walk = cur; |
| 163 | cur = swap; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // Reverse topological sort into the original head node |
| 169 | while (list.mProcessLink.next != &list) |
| 170 | { |
| 171 | ProcessObject * ptr = list.mProcessLink.next; |
| 172 | ProcessObject * afterObject = ptr->getAfterObject(); |
| 173 | ptr->mProcessTag = mCurrentTag; |
| 174 | ptr->plUnlink(); |
| 175 | if (afterObject) |
| 176 | { |
| 177 | // Build chain "stack" of dependent objects and patch |
| 178 | // it to the end of the current list. |
| 179 | while (afterObject && afterObject->mProcessTag != mCurrentTag) |
| 180 | { |
| 181 | afterObject->mProcessTag = mCurrentTag; |
| 182 | afterObject->plUnlink(); |
| 183 | afterObject->plLinkBefore(ptr); |
| 184 | ptr = afterObject; |
| 185 | afterObject = ptr->getAfterObject(); |
| 186 | } |
| 187 | ptr->plJoin(&mHead); |
nothing calls this directly
no test coverage detected