Skip to content

Commit 576ced5

Browse files
authored
[clang][bytecode] Simplify Block::replacePointer() (#144490)
Try to do less work here instead of a full remove + add.
1 parent ce96fdd commit 576ced5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

clang/lib/AST/ByteCode/InterpBlock.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,26 @@ void Block::cleanup() {
6969
void Block::replacePointer(Pointer *Old, Pointer *New) {
7070
assert(Old);
7171
assert(New);
72+
assert(Old != New);
7273
if (IsStatic) {
7374
assert(!Pointers);
7475
return;
7576
}
76-
7777
#ifndef NDEBUG
7878
assert(hasPointer(Old));
7979
#endif
8080

81-
removePointer(Old);
82-
addPointer(New);
81+
if (Old->Prev)
82+
Old->Prev->Next = New;
83+
if (Old->Next)
84+
Old->Next->Prev = New;
85+
New->Prev = Old->Prev;
86+
New->Next = Old->Next;
87+
if (Pointers == Old)
88+
Pointers = New;
8389

8490
Old->PointeeStorage.BS.Pointee = nullptr;
85-
91+
New->PointeeStorage.BS.Pointee = this;
8692
#ifndef NDEBUG
8793
assert(!hasPointer(Old));
8894
assert(hasPointer(New));

0 commit comments

Comments
 (0)