Skip to content

Commit

Permalink
freeze MatchContext after matching process
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Sep 7, 2024
1 parent 1bd2d06 commit 7fa00c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public MatchContext matchResult(MatchContext context) {
context.collectedInsns().add(context.insn());

// We have match!
return context;
return context.freeze();
}

// We don't have match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import uwu.narumi.deobfuscator.api.asm.InstructionContext;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Immutable match context
* Immutable match context. After matching process, the context is frozen by {@link MatchContext#freeze()}
*
* @param insnContext Instruction context
* @param storage Storage for saving some instructions in matching process. id -> match context
Expand All @@ -26,8 +27,12 @@ public static MatchContext of(InstructionContext insnContext) {
return new MatchContext(insnContext, new HashMap<>(), new ArrayList<>());
}

public MatchContext freeze() {
return new MatchContext(this.insnContext, Collections.unmodifiableMap(this.storage), Collections.unmodifiableList(this.collectedInsns));
}

/**
* Merges other context into this context
* Merges other {@link MatchContext} into this {@link MatchContext}
*/
public void merge(MatchContext other) {
this.storage.putAll(other.storage);
Expand Down

0 comments on commit 7fa00c0

Please sign in to comment.