703 {
704 const intptr_t
length = table_.length();
706 table_.Add(new_code);
708 }
709
710
711 intptr_t lo = -1;
712 intptr_t hi = -1;
713 ProfileCode* lo_code = nullptr;
714 ProfileCode* hi_code = nullptr;
715 const uword pc = new_code->end() - 1;
716 FindNeighbors(pc, &lo, &hi, &lo_code, &hi_code);
717 ASSERT((lo_code !=
nullptr) || (hi_code !=
nullptr));
718
719 if (lo != -1) {
720
721 new_code->TruncateLower(lo_code->end());
722 ASSERT(!new_code->Overlaps(lo_code));
723 }
724 if (hi != -1) {
725
726 new_code->TruncateUpper(hi_code->start());
727 ASSERT(!new_code->Overlaps(hi_code));
728 }
729
732 (lo_code->end() == new_code->start())) {
733
734
735
736 lo_code->ExpandUpper(new_code->end());
737 return lo;
738 }
739
742 (new_code->end() == hi_code->start())) {
743
744
745
746 hi_code->ExpandLower(new_code->start());
747 return hi;
748 }
749
750 intptr_t insert;
751 if (lo == -1) {
752 insert = 0;
753 } else if (hi == -1) {
755 } else {
756 insert = lo + 1;
757 }
758 table_.InsertAt(insert, new_code);
759 return insert;
760}