1.1 --- a/src/share/classes/com/sun/tools/javac/util/ByteBuffer.java Tue Sep 25 11:56:46 2012 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/util/ByteBuffer.java Tue Sep 25 13:06:58 2012 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -60,16 +60,10 @@ 1.11 length = 0; 1.12 } 1.13 1.14 - private void copy(int size) { 1.15 - byte[] newelems = new byte[size]; 1.16 - System.arraycopy(elems, 0, newelems, 0, elems.length); 1.17 - elems = newelems; 1.18 - } 1.19 - 1.20 /** Append byte to this buffer. 1.21 */ 1.22 public void appendByte(int b) { 1.23 - if (length >= elems.length) copy(elems.length * 2); 1.24 + elems = ArrayUtils.ensureCapacity(elems, length); 1.25 elems[length++] = (byte)b; 1.26 } 1.27 1.28 @@ -77,7 +71,7 @@ 1.29 * starting at given `start' offset. 1.30 */ 1.31 public void appendBytes(byte[] bs, int start, int len) { 1.32 - while (length + len > elems.length) copy(elems.length * 2); 1.33 + elems = ArrayUtils.ensureCapacity(elems, length + len); 1.34 System.arraycopy(bs, start, elems, length, len); 1.35 length += len; 1.36 } 1.37 @@ -91,7 +85,7 @@ 1.38 /** Append a character as a two byte number. 1.39 */ 1.40 public void appendChar(int x) { 1.41 - while (length + 1 >= elems.length) copy(elems.length * 2); 1.42 + elems = ArrayUtils.ensureCapacity(elems, length + 1); 1.43 elems[length ] = (byte)((x >> 8) & 0xFF); 1.44 elems[length+1] = (byte)((x ) & 0xFF); 1.45 length = length + 2; 1.46 @@ -100,7 +94,7 @@ 1.47 /** Append an integer as a four byte number. 1.48 */ 1.49 public void appendInt(int x) { 1.50 - while (length + 3 >= elems.length) copy(elems.length * 2); 1.51 + elems = ArrayUtils.ensureCapacity(elems, length + 3); 1.52 elems[length ] = (byte)((x >> 24) & 0xFF); 1.53 elems[length+1] = (byte)((x >> 16) & 0xFF); 1.54 elems[length+2] = (byte)((x >> 8) & 0xFF);