# HG changeset patch # User Gilles Duboscq # Date 1382026685 -7200 # Node ID 47200418768d752d43967412397294452ca16b74 # Parent 36a438ebab50543b690034967614ee1536e4bdfe Small optimizations to Binary Printer and IGV's BinaryParser diff -r 36a438ebab50 -r 47200418768d graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java --- 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); } } diff -r 36a438ebab50 -r 47200418768d src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java --- 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); }