From 234073efb2079e20a983c4dd5993ce53cca8bfe6 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 20 Apr 2017 19:11:52 +0300 Subject: [PATCH] specify the exact collection size when we know --- src/org/jetbrains/java/decompiler/struct/StructClass.java | 6 +++--- src/org/jetbrains/java/decompiler/struct/StructMember.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/struct/StructClass.java b/src/org/jetbrains/java/decompiler/struct/StructClass.java index 33dc178..fafd5f8 100644 --- a/src/org/jetbrains/java/decompiler/struct/StructClass.java +++ b/src/org/jetbrains/java/decompiler/struct/StructClass.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -93,7 +93,7 @@ public class StructClass extends StructMember { // fields length = in.readUnsignedShort(); - fields = new VBStyleCollection<>(); + fields = new VBStyleCollection<>(length); for (int i = 0; i < length; i++) { StructField field = new StructField(in, this); fields.addWithKey(field, InterpreterUtil.makeUniqueKey(field.getName(), field.getDescriptor())); @@ -101,7 +101,7 @@ public class StructClass extends StructMember { // methods length = in.readUnsignedShort(); - methods = new VBStyleCollection<>(); + methods = new VBStyleCollection<>(length); for (int i = 0; i < length; i++) { StructMethod method = new StructMethod(in, this); methods.addWithKey(method, InterpreterUtil.makeUniqueKey(method.getName(), method.getDescriptor())); diff --git a/src/org/jetbrains/java/decompiler/struct/StructMember.java b/src/org/jetbrains/java/decompiler/struct/StructMember.java index 86f79b4..bfe2270 100644 --- a/src/org/jetbrains/java/decompiler/struct/StructMember.java +++ b/src/org/jetbrains/java/decompiler/struct/StructMember.java @@ -48,9 +48,9 @@ public class StructMember { } protected VBStyleCollection readAttributes(DataInputFullStream in, ConstantPool pool) throws IOException { - VBStyleCollection attributes = new VBStyleCollection<>(); - int length = in.readUnsignedShort(); + + VBStyleCollection attributes = new VBStyleCollection<>(length); for (int i = 0; i < length; i++) { int nameIndex = in.readUnsignedShort(); String name = pool.getPrimitiveConstant(nameIndex).getString();