8008096: TokenStream buffer should grow exponentially
authorhannesw
Wed, 13 Feb 2013 13:30:21 +0100
changeset 16229 cab69ca3490d
parent 16228 df28320aa080
child 16230 c38c724d82e7
8008096: TokenStream buffer should grow exponentially Reviewed-by: attila, lagergren, sundar
nashorn/src/jdk/nashorn/internal/parser/TokenStream.java
--- a/nashorn/src/jdk/nashorn/internal/parser/TokenStream.java	Tue Feb 12 12:47:51 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/parser/TokenStream.java	Wed Feb 13 13:30:21 2013 +0100
@@ -34,8 +34,8 @@
  *
  */
 public class TokenStream {
-    /** Buffer growth factor. */
-    private static final int growth = 256;
+    /** Initial buffer size. */
+    private static final int INITIAL_SIZE = 256;
 
     /** Token buffer. */
     private long[] buffer;
@@ -56,7 +56,7 @@
      * Constructor.
      */
     public TokenStream() {
-        buffer = new long[growth];
+        buffer = new long[INITIAL_SIZE];
         count = 0;
         in = 0;
         out = 0;
@@ -193,7 +193,7 @@
      */
     public void grow() {
         // Allocate new buffer.
-        final long[] newBuffer = new long[buffer.length + growth];
+        final long[] newBuffer = new long[buffer.length * 2];
 
         // If single chunk.
         if (in > out) {