diff --git a/src/include/interval_set.h b/src/include/interval_set.h index b84d8187052d6..e05eacae41efa 100644 --- a/src/include/interval_set.h +++ b/src/include/interval_set.h @@ -463,17 +463,31 @@ class interval_set { typename std::map::const_iterator pa = a.m.begin(); typename std::map::const_iterator pb = b.m.begin(); - + typename decltype(m)::iterator mi = m.begin(); + while (pa != a.m.end() && pb != b.m.end()) { // passing? if (pa->first + pa->second <= pb->first) { pa++; continue; } if (pb->first + pb->second <= pa->first) { pb++; continue; } + + if (*pa == *pb) { + do { + mi = m.insert(mi, *pa); + _size += pa->second; + ++pa; + ++pb; + } while (pa != a.m.end() && pb != b.m.end() && *pa == *pb); + continue; + } + T start = MAX(pa->first, pb->first); T en = MIN(pa->first+pa->second, pb->first+pb->second); assert(en > start); - insert(start, en-start); + typename decltype(m)::value_type i{start, en - start}; + mi = m.insert(mi, i); + _size += i.second; if (pa->first+pa->second > pb->first+pb->second) pb++; else