| 254 | |
| 255 | template<class I> |
| 256 | forceinline void |
| 257 | RangeList::insert(Space& home, RangeList*& r, I& i) { |
| 258 | RangeList sentinel; |
| 259 | sentinel.next(r); |
| 260 | RangeList* p = &sentinel; |
| 261 | RangeList* c = p->next(); |
| 262 | while ((c != nullptr) && i()) { |
| 263 | if ((c->max()+1 < i.min())) { |
| 264 | p=c; c=c->next(); |
| 265 | } else if (i.max()+1 < c->min()) { |
| 266 | RangeList* n = new (home) RangeList(i.min(),i.max(),c); |
| 267 | p->next(n); p=n; ++i; |
| 268 | } else { |
| 269 | int min = std::min(c->min(),i.min()); |
| 270 | int max = std::max(c->max(),i.max()); |
| 271 | RangeList* f=c; |
| 272 | p=c; c=c->next(); ++i; |
| 273 | next: |
| 274 | if ((c != nullptr) && (c->min() <= max+1)) { |
| 275 | max = std::max(max,c->max()); |
| 276 | p=c; c=c->next(); |
| 277 | goto next; |
| 278 | } |
| 279 | if (i() && (i.min() <= max+1)) { |
| 280 | max = std::max(max,i.max()); |
| 281 | ++i; |
| 282 | goto next; |
| 283 | } |
| 284 | // Dispose now unused elements |
| 285 | if (f->next() != p) |
| 286 | f->next()->dispose(home,p); |
| 287 | f->min(min); f->max(max); f->next(c); |
| 288 | } |
| 289 | } |
| 290 | if (c == nullptr) { |
| 291 | while (i()) { |
| 292 | RangeList* n = new (home) RangeList(i.min(),i.max()); |
| 293 | p->next(n); p=n; |
| 294 | ++i; |
| 295 | } |
| 296 | p->next(nullptr); |
| 297 | } |
| 298 | r = sentinel.next(); |
| 299 | } |
| 300 | |
| 301 | } |
| 302 | // STATISTICS: kernel-other |