changeset 12480:47200418768d

Small optimizations to Binary Printer and IGV's BinaryParser
author Gilles Duboscq <duboscq@ssw.jku.at>
date Thu, 17 Oct 2013 18:18:05 +0200
parents 36a438ebab50
children 45daf0d65522
files graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java
diffstat 2 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Fri Oct 18 14:51:56 2013 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Thu Oct 17 18:18:05 2013 +0200
@@ -149,6 +149,7 @@
     }
 
     private void ensureAvailable(int i) throws IOException {
+        assert buffer.capacity() >= i : "Can not make " + i + " bytes available, buffer is too small";
         while (buffer.remaining() < i) {
             flush();
         }
@@ -186,10 +187,10 @@
 
     private void writeString(String str) throws IOException {
         writeInt(str.length());
-        ensureAvailable(str.length() * 2);
-        for (int i = 0; i < str.length(); i++) {
-            buffer.putChar(str.charAt(i));
-        }
+        int sizeInBytes = str.length() * 2;
+        ensureAvailable(sizeInBytes);
+        buffer.asCharBuffer().put(str);
+        buffer.position(buffer.position() + sizeInBytes);
     }
 
     private void writeBytes(byte[] b) throws IOException {
@@ -207,10 +208,10 @@
             writeInt(-1);
         } else {
             writeInt(b.length);
-            ensureAvailable(b.length * 4);
-            for (int i = 0; i < b.length; i++) {
-                buffer.putInt(b[i]);
-            }
+            int sizeInBytes = b.length * 4;
+            ensureAvailable(sizeInBytes);
+            buffer.asIntBuffer().put(b);
+            buffer.position(buffer.position() + sizeInBytes);
         }
     }
 
@@ -219,10 +220,10 @@
             writeInt(-1);
         } else {
             writeInt(b.length);
-            ensureAvailable(b.length * 8);
-            for (int i = 0; i < b.length; i++) {
-                buffer.putDouble(b[i]);
-            }
+            int sizeInBytes = b.length * 8;
+            ensureAvailable(sizeInBytes);
+            buffer.asDoubleBuffer().put(b);
+            buffer.position(buffer.position() + sizeInBytes);
         }
     }
 
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java	Fri Oct 18 14:51:56 2013 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java	Thu Oct 17 18:18:05 2013 +0200
@@ -301,9 +301,8 @@
         int len = readInt();
         ensureAvailable(len * 2);
         char[] chars = new char[len];
-        for (int i = 0; i < len; i++) {
-            chars[i] = buffer.getChar();
-        }
+        buffer.asCharBuffer().get(chars);
+        buffer.position(buffer.position() + len * 2);
         return new String(chars);
     }