From 5770d25e599126c1dac0a0cc45bddbdbe972dfb9 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 25 Mar 2015 19:12:33 +0300 Subject: [PATCH] decompiler: create less thrown away objects - pt.2 --- .../java/decompiler/code/ExceptionTable.java | 15 +++++++++------ .../decompiler/code/FullInstructionSequence.java | 4 ++-- .../decompiler/code/InstructionSequence.java | 16 ++++++++++++---- .../code/SimpleInstructionSequence.java | 4 ++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/code/ExceptionTable.java b/src/org/jetbrains/java/decompiler/code/ExceptionTable.java index e828a7f..533fa55 100644 --- a/src/org/jetbrains/java/decompiler/code/ExceptionTable.java +++ b/src/org/jetbrains/java/decompiler/code/ExceptionTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,18 @@ package org.jetbrains.java.decompiler.code; import org.jetbrains.java.decompiler.code.interpreter.Util; import org.jetbrains.java.decompiler.struct.StructContext; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class ExceptionTable { + public static final ExceptionTable EMPTY = new ExceptionTable(null) { + @Override + public List getHandlers() { + return Collections.emptyList(); + } + }; - private List handlers = new ArrayList(); - - public ExceptionTable() { - } + private final List handlers; public ExceptionTable(List handlers) { this.handlers = handlers; diff --git a/src/org/jetbrains/java/decompiler/code/FullInstructionSequence.java b/src/org/jetbrains/java/decompiler/code/FullInstructionSequence.java index eb8f819..ae5d4f2 100644 --- a/src/org/jetbrains/java/decompiler/code/FullInstructionSequence.java +++ b/src/org/jetbrains/java/decompiler/code/FullInstructionSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ public class FullInstructionSequence extends InstructionSequence { // ***************************************************************************** public FullInstructionSequence(VBStyleCollection collinstr, ExceptionTable extable) { - this.collinstr = collinstr; + super(collinstr); this.exceptionTable = extable; // translate raw exception handlers to instr diff --git a/src/org/jetbrains/java/decompiler/code/InstructionSequence.java b/src/org/jetbrains/java/decompiler/code/InstructionSequence.java index 709a85d..705db4e 100644 --- a/src/org/jetbrains/java/decompiler/code/InstructionSequence.java +++ b/src/org/jetbrains/java/decompiler/code/InstructionSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,11 +34,19 @@ public abstract class InstructionSequence { // private fields // ***************************************************************************** - protected VBStyleCollection collinstr = new VBStyleCollection(); + protected final VBStyleCollection collinstr; protected int pointer = 0; - protected ExceptionTable exceptionTable = new ExceptionTable(); + protected ExceptionTable exceptionTable = ExceptionTable.EMPTY; + + protected InstructionSequence() { + this(new VBStyleCollection()); + } + + protected InstructionSequence(VBStyleCollection collinstr) { + this.collinstr = collinstr; + } // ***************************************************************************** // public methods @@ -52,7 +60,7 @@ public abstract class InstructionSequence { public void clear() { collinstr.clear(); pointer = 0; - exceptionTable = new ExceptionTable(); + exceptionTable = ExceptionTable.EMPTY; } public void addInstruction(Instruction inst, int offset) { diff --git a/src/org/jetbrains/java/decompiler/code/SimpleInstructionSequence.java b/src/org/jetbrains/java/decompiler/code/SimpleInstructionSequence.java index bcc3c4a..5963509 100644 --- a/src/org/jetbrains/java/decompiler/code/SimpleInstructionSequence.java +++ b/src/org/jetbrains/java/decompiler/code/SimpleInstructionSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ public class SimpleInstructionSequence extends InstructionSequence { } public SimpleInstructionSequence(VBStyleCollection collinstr) { - this.collinstr = collinstr; + super(collinstr); } public SimpleInstructionSequence clone() {