- e->size = start - e->start;
- i++;
- if (end < e_end)
- // Need to split existing item
- insert_e820(i, end, e_end - end, e->type);
- }
- insert_e820(i, start, size, type);
- i++;
- // Remove all existing items that are completely overlapped.
- while (i<e820_count) {
- e = &e820_list[i];
- if (end <= e->start)
- break;
- e_end = e->start + e->size;
- if (end < e_end) {
- // Existing item not completely overlapped - adjust its start.
- e->start = end;
- e->size = e_end - e->start;
- break;
+ if (type == e->type) {
+ // Same type - merge them.
+ size += start - e->start;
+ start = e->start;
+ } else {
+ // Split existing item.
+ e->size = start - e->start;
+ i++;
+ if (e_end > end)
+ insert_e820(i, end, e_end - end, e->type);