- if (ignored_regions_.empty()) {
- ignored_regions_.push_back(region);
- return;
- }
-
- unsigned int cursor = 0;
- const IgnoredRegion* current_region = nullptr;
-
- int start = 0;
- int end = ignored_regions_.size() - 1;
- while (start <= end) {
- cursor = (start + end) / 2;
- current_region = &ignored_regions_[cursor];
- if (current_region->addr == addr) {
- if (current_region->size == size)
- return;
- else if (current_region->size < size)
- start = cursor + 1;
- else
- end = cursor - 1;
- } else if (current_region->addr < addr)
- start = cursor + 1;
- else
- end = cursor - 1;
- }
-
- std::size_t position;
- if (current_region->addr == addr) {
- if (current_region->size < size)
- position = cursor + 1;
- else
- position = cursor;
- } else if (current_region->addr < addr)
- position = cursor + 1;
- else
- position = cursor;
- ignored_regions_.insert(ignored_regions_.begin() + position, region);
+ auto pos = std::lower_bound(ignored_regions_.begin(), ignored_regions_.end(), region,
+ [](auto const& reg1, auto const& reg2) {
+ return reg1.addr < reg2.addr || (reg1.addr == reg2.addr && reg1.size < reg2.size);
+ });
+ if (pos == ignored_regions_.end() || pos->addr != addr || pos->size != size)
+ ignored_regions_.insert(pos, region);