avoid stream to array copying

master
Egor.Ushakov 8 years ago
parent 0255eb3ba5
commit 6a09fe2524
  1. 4
      src/org/jetbrains/java/decompiler/struct/StructMember.java
  2. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructAnnDefaultAttribute.java
  3. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationAttribute.java
  4. 8
      src/org/jetbrains/java/decompiler/struct/attr/StructAnnotationParameterAttribute.java
  5. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructBootstrapMethodsAttribute.java
  6. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructConstantValueAttribute.java
  7. 6
      src/org/jetbrains/java/decompiler/struct/attr/StructEnclosingMethodAttribute.java
  8. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructExceptionsAttribute.java
  9. 11
      src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java
  10. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructGenericSignatureAttribute.java
  11. 8
      src/org/jetbrains/java/decompiler/struct/attr/StructInnerClassesAttribute.java
  12. 6
      src/org/jetbrains/java/decompiler/struct/attr/StructLineNumberTableAttribute.java
  13. 6
      src/org/jetbrains/java/decompiler/struct/attr/StructLocalVariableTableAttribute.java
  14. 4
      src/org/jetbrains/java/decompiler/struct/attr/StructLocalVariableTypeTableAttribute.java
  15. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructSourceFileAttribute.java
  16. 7
      src/org/jetbrains/java/decompiler/struct/attr/StructTypeAnnotationAttribute.java

@ -84,9 +84,7 @@ public class StructMember {
in.discard(length); in.discard(length);
} }
else { else {
byte[] data = in.read(length); attribute.initContent(in, pool);
attribute.setInfo(data);
attribute.initContent(pool);
} }
return attribute; return attribute;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent; import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.IOException; import java.io.IOException;
@ -25,8 +26,8 @@ public class StructAnnDefaultAttribute extends StructGeneralAttribute {
private Exprent defaultValue; private Exprent defaultValue;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
defaultValue = StructAnnotationAttribute.parseAnnotationElement(stream(), pool); defaultValue = StructAnnotationAttribute.parseAnnotationElement(data, pool);
} }
public Exprent getDefaultValue() { public Exprent getDefaultValue() {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant; import org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant;
import org.jetbrains.java.decompiler.struct.gen.FieldDescriptor; import org.jetbrains.java.decompiler.struct.gen.FieldDescriptor;
import org.jetbrains.java.decompiler.struct.gen.VarType; import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -32,8 +33,8 @@ public class StructAnnotationAttribute extends StructGeneralAttribute {
private List<AnnotationExprent> annotations; private List<AnnotationExprent> annotations;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
annotations = parseAnnotations(pool, stream()); annotations = parseAnnotations(pool, data);
} }
public static List<AnnotationExprent> parseAnnotations(ConstantPool pool, DataInputStream data) throws IOException { public static List<AnnotationExprent> parseAnnotations(ConstantPool pool, DataInputStream data) throws IOException {

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent; import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -29,9 +29,7 @@ public class StructAnnotationParameterAttribute extends StructGeneralAttribute {
private List<List<AnnotationExprent>> paramAnnotations; private List<List<AnnotationExprent>> paramAnnotations;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputStream data = stream();
int len = data.readUnsignedByte(); int len = data.readUnsignedByte();
if (len > 0) { if (len > 0) {
paramAnnotations = new ArrayList<>(len); paramAnnotations = new ArrayList<>(len);

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2015 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.struct.consts.LinkConstant; import org.jetbrains.java.decompiler.struct.consts.LinkConstant;
import org.jetbrains.java.decompiler.struct.consts.PooledConstant; import org.jetbrains.java.decompiler.struct.consts.PooledConstant;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -30,9 +31,7 @@ public class StructBootstrapMethodsAttribute extends StructGeneralAttribute {
private final List<List<PooledConstant>> methodArguments = new ArrayList<>(); private final List<List<PooledConstant>> methodArguments = new ArrayList<>();
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputStream data = stream();
int method_number = data.readUnsignedShort(); int method_number = data.readUnsignedShort();
for (int i = 0; i < method_number; ++i) { for (int i = 0; i < method_number; ++i) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.struct.attr; package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.IOException; import java.io.IOException;
@ -24,8 +25,8 @@ public class StructConstantValueAttribute extends StructGeneralAttribute {
private int index; private int index;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
index = stream().readUnsignedShort(); index = data.readUnsignedShort();
} }
public int getIndex() { public int getIndex() {

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.struct.consts.LinkConstant; import org.jetbrains.java.decompiler.struct.consts.LinkConstant;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -28,8 +29,7 @@ public class StructEnclosingMethodAttribute extends StructGeneralAttribute {
private String methodDescriptor; private String methodDescriptor;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputStream data = stream();
int classIndex = data.readUnsignedShort(); int classIndex = data.readUnsignedShort();
int methodIndex = data.readUnsignedShort(); int methodIndex = data.readUnsignedShort();

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,8 @@
package org.jetbrains.java.decompiler.struct.attr; package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -28,8 +28,7 @@ public class StructExceptionsAttribute extends StructGeneralAttribute {
private List<Integer> throwsExceptions; private List<Integer> throwsExceptions;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputStream data = stream();
int len = data.readUnsignedShort(); int len = data.readUnsignedShort();
if (len > 0) { if (len > 0) {
throwsExceptions = new ArrayList<>(len); throwsExceptions = new ArrayList<>(len);

@ -50,7 +50,6 @@ public class StructGeneralAttribute {
public static final String ATTRIBUTE_SOURCE_FILE = "SourceFile"; public static final String ATTRIBUTE_SOURCE_FILE = "SourceFile";
private String name; private String name;
private byte[] info;
public static StructGeneralAttribute createAttribute(String name) { public static StructGeneralAttribute createAttribute(String name) {
StructGeneralAttribute attr; StructGeneralAttribute attr;
@ -109,15 +108,7 @@ public class StructGeneralAttribute {
return attr; return attr;
} }
protected DataInputFullStream stream() { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { }
return new DataInputFullStream(info);
}
public void initContent(ConstantPool pool) throws IOException { }
public void setInfo(byte[] info) {
this.info = info;
}
public String getName() { public String getName() {
return name; return name;

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.struct.attr; package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.IOException; import java.io.IOException;
@ -24,8 +25,8 @@ public class StructGenericSignatureAttribute extends StructGeneralAttribute {
private String signature; private String signature;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
int index = stream().readUnsignedShort(); int index = data.readUnsignedShort();
signature = pool.getPrimitiveConstant(index).getString(); signature = pool.getPrimitiveConstant(index).getString();
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2015 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,8 @@
package org.jetbrains.java.decompiler.struct.attr; package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -47,9 +47,7 @@ public class StructInnerClassesAttribute extends StructGeneralAttribute {
private List<Entry> entries; private List<Entry> entries;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputStream data = stream();
int len = data.readUnsignedShort(); int len = data.readUnsignedShort();
if (len > 0) { if (len > 0) {
entries = new ArrayList<>(len); entries = new ArrayList<>(len);

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,9 +33,7 @@ public class StructLineNumberTableAttribute extends StructGeneralAttribute {
private int[] myLineInfo = InterpreterUtil.EMPTY_INT_ARRAY; private int[] myLineInfo = InterpreterUtil.EMPTY_INT_ARRAY;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputFullStream data = stream();
int len = data.readUnsignedShort() * 2; int len = data.readUnsignedShort() * 2;
if (len > 0) { if (len > 0) {
myLineInfo = new int[len]; myLineInfo = new int[len];

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,9 +38,7 @@ public class StructLocalVariableTableAttribute extends StructGeneralAttribute {
private Map<Integer, String> mapVarNames = Collections.emptyMap(); private Map<Integer, String> mapVarNames = Collections.emptyMap();
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputFullStream data = stream();
int len = data.readUnsignedShort(); int len = data.readUnsignedShort();
if (len > 0) { if (len > 0) {
mapVarNames = new HashMap<>(len); mapVarNames = new HashMap<>(len);

@ -37,9 +37,7 @@ public class StructLocalVariableTypeTableAttribute extends StructGeneralAttribut
private Map<Integer, String> mapVarSignatures = Collections.emptyMap(); private Map<Integer, String> mapVarSignatures = Collections.emptyMap();
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputFullStream data = stream();
int len = data.readUnsignedShort(); int len = data.readUnsignedShort();
if (len > 0) { if (len > 0) {
mapVarSignatures = new HashMap<>(len); mapVarSignatures = new HashMap<>(len);

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2015 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.jetbrains.java.decompiler.struct.attr; package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.IOException; import java.io.IOException;
@ -24,8 +25,8 @@ public class StructSourceFileAttribute extends StructGeneralAttribute {
private String fileName; private String fileName;
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
int index = stream().readUnsignedShort(); int index = data.readUnsignedShort();
fileName = pool.getPrimitiveConstant(index).getString(); fileName = pool.getPrimitiveConstant(index).getString();
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent; import org.jetbrains.java.decompiler.modules.decompiler.exps.AnnotationExprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.TypeAnnotation; import org.jetbrains.java.decompiler.modules.decompiler.exps.TypeAnnotation;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool; import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -29,9 +30,7 @@ public class StructTypeAnnotationAttribute extends StructGeneralAttribute {
private List<TypeAnnotation> annotations = Collections.emptyList(); private List<TypeAnnotation> annotations = Collections.emptyList();
@Override @Override
public void initContent(ConstantPool pool) throws IOException { public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
DataInputStream data = stream();
int len = data.readUnsignedShort(); int len = data.readUnsignedShort();
if (len > 0) { if (len > 0) {
annotations = new ArrayList<>(len); annotations = new ArrayList<>(len);

Loading…
Cancel
Save