MCPcopy Create free account
hub / github.com/KDE/kdiff3 / insertEntry

Method insertEntry

src/diff.cpp:529–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

527}
528
529void ManualDiffHelpList::insertEntry(e_SrcSelector winIdx, LineRef firstLine, LineRef lastLine)
530{
531 // The manual diff help list must be sorted and compact.
532 // "Compact" means that upper items can't be empty if lower items contain data.
533
534 // First insert the new item without regarding compactness.
535 // If the new item overlaps with previous items then the previous items will be removed.
536
537 ManualDiffHelpEntry mdhe(winIdx, firstLine, lastLine);
538
539 ManualDiffHelpList::iterator i;
540 for(i = begin(); i != end(); ++i)
541 {
542 LineRef& l1 = i->firstLine(winIdx);
543 LineRef& l2 = i->lastLine(winIdx);
544 if(l1.isValid() && l2.isValid())
545 {
546 if((firstLine <= l1 && lastLine >= l1) || (firstLine <= l2 && lastLine >= l2))
547 {
548 // overlap
549 l1.invalidate();
550 l2.invalidate();
551 }
552 else if(firstLine < l1 && lastLine < l1)
553 {
554 // insert before this position
555 insert(i, mdhe);
556 break;
557 }
558 }
559 }
560 if(i == end())
561 {
562 insert(i, mdhe);
563 }
564
565 // Now make the list compact
566 for(i = begin(); i != end();)
567 {
568 ManualDiffHelpList::iterator next = std::next(i);
569 if(next != end())
570 {
571 for(e_SrcSelector wIdx = e_SrcSelector::A; wIdx != e_SrcSelector::Invalid; wIdx = nextSelector(wIdx))
572 {
573 if(!i->firstLine(wIdx).isValid() && next->firstLine(wIdx).isValid())
574 {
575 std::swap(i->firstLine(wIdx), next->firstLine(wIdx));
576 std::swap(i->lastLine(wIdx), next->lastLine(wIdx));
577 }
578 }
579 }
580 //Delete completely empty entries
581 if(*i == ManualDiffHelpEntry())
582 erase(i);
583 i = next;
584 }
585}
586

Callers 4

slotAddManualDiffHelpMethod · 0.80
testListKeeptSortedMethod · 0.80
testDeleteAndSortMethod · 0.80

Calls 4

nextSelectorFunction · 0.85
ManualDiffHelpEntryClass · 0.85
invalidateMethod · 0.80
isValidMethod · 0.45

Tested by 2

testListKeeptSortedMethod · 0.64
testDeleteAndSortMethod · 0.64