Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary linked list traversals in MethodLinker. #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions base/src/main/java/proguard/classfile/util/MethodLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import static proguard.classfile.instruction.Instruction.OP_INVOKESTATIC;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import proguard.classfile.AccessConstants;
import proguard.classfile.Clazz;
Expand Down Expand Up @@ -132,12 +134,19 @@ private static void link(Member member1, Member member2) {
* @return The last method in the linked list.
*/
public static Member lastMember(Member member) {
List<Member> chain = new ArrayList<>();
Member lastMember = member;
while (lastMember.getProcessingInfo() != null
&& lastMember.getProcessingInfo() instanceof Member) {
chain.add(lastMember);
lastMember = (Member) lastMember.getProcessingInfo();
}

// Point every member in the chain directly to the last element to save time in the future
for (Member relatedMember : chain) {
relatedMember.setProcessingInfo(lastMember);
}

return lastMember;
}

Expand All @@ -149,6 +158,9 @@ public static Member lastMember(Member member) {
*/
public static Processable lastProcessable(Processable processable) {
Processable lastProcessable = processable;
if (lastProcessable instanceof Member) {
lastProcessable = lastMember((Member) lastProcessable);
}
while (lastProcessable.getProcessingInfo() != null
&& lastProcessable.getProcessingInfo() instanceof Processable) {
lastProcessable = (Processable) lastProcessable.getProcessingInfo();
Expand Down
Loading