[COMMITTED] BinaryImporter speed up

BinaryImporter uses ByteArrayOutputStream to read data.

It is created by default constructor(the initial byte array size is 32) everytime load() is called.

So internally it creates many byte array and it degrades loading performance.

We need to reuse OutputStream.



Index: src/com/jme/util/export/binary/BinaryImporter.java
===================================================================
--- src/com/jme/util/export/binary/BinaryImporter.java   (revision 4095)
+++ src/com/jme/util/export/binary/BinaryImporter.java   (working copy)
@@ -83,10 +83,14 @@
     }
 
     public Savable load(InputStream is) throws IOException {
-        return load(is, null);
+        return load(is, null, null);
     }
-
+   
     public Savable load(InputStream is, ReadListener listener) throws IOException {
+       return load(is, listener, null);
+    }
+   
+    public Savable load(InputStream is, ReadListener listener, ByteArrayOutputStream baos) throws IOException {
         contentTable = new HashMap<Integer, Savable>();
         GZIPInputStream zis = new GZIPInputStream(is);
         BufferedInputStream bis = new BufferedInputStream(zis);
@@ -141,7 +145,9 @@
         bytes += 8;
         if (listener != null) listener.readBytes(bytes);
 
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        if (baos == null) {
+           baos = new ByteArrayOutputStream(bytes);
+        }
         int size = -1;
         byte[] cache = new byte[4096];
         while((size = bis.read(cache)) != -1) {

nice  :), is it tested and how much performance boost do we get with this?

Not much, but if it is heavy loading process,

it speeds up somewhat. (in case of my project)

I'll find another culprits  :slight_smile:

Added ByteArrayOutputStream.reset() call. (reset to be reused)

Test is done and works well.



Index: src/com/jme/util/export/binary/BinaryImporter.java
===================================================================
--- src/com/jme/util/export/binary/BinaryImporter.java   (revision 4095)
+++ src/com/jme/util/export/binary/BinaryImporter.java   (working copy)
@@ -83,10 +83,14 @@
     }
 
     public Savable load(InputStream is) throws IOException {
-        return load(is, null);
+        return load(is, null, null);
     }
-
+   
     public Savable load(InputStream is, ReadListener listener) throws IOException {
+       return load(is, listener, null);
+    }
+   
+    public Savable load(InputStream is, ReadListener listener, ByteArrayOutputStream baos) throws IOException {
         contentTable = new HashMap<Integer, Savable>();
         GZIPInputStream zis = new GZIPInputStream(is);
         BufferedInputStream bis = new BufferedInputStream(zis);
@@ -141,7 +145,11 @@
         bytes += 8;
         if (listener != null) listener.readBytes(bytes);
 
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        if (baos == null) {
+           baos = new ByteArrayOutputStream(bytes);
+        } else {
+           baos.reset();
+        }
         int size = -1;
         byte[] cache = new byte[4096];
         while((size = bis.read(cache)) != -1) {