directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r385102 - /directory/trunks/mina/core/src/main/java/org/apache/mina/common/ByteBuffer.java
Date Sat, 11 Mar 2006 16:15:06 GMT
Author: trustin
Date: Sat Mar 11 08:15:05 2006
New Revision: 385102

URL: http://svn.apache.org/viewcvs?rev=385102&view=rev
Log:
* Optimized ByteBuffer.putString() more
* Modified Peter's patch a little bit to make sure the state is reset


Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/ByteBuffer.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/ByteBuffer.java?rev=385102&r1=385101&r2=385102&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/ByteBuffer.java Sat Mar
11 08:15:05 2006
@@ -1086,10 +1086,10 @@
         }
         
         CharBuffer in = CharBuffer.wrap( val ); 
-        int expectedLength = (int) (in.remaining() * encoder.averageBytesPerChar()) + 1;
-        
         encoder.reset();
         
+        int expandedState = 0;
+        
         for (;;) {
             CoderResult cr;
             if( in.hasRemaining() )
@@ -1105,10 +1105,31 @@
             {
                 break;
             }
-            if( cr.isOverflow() && isAutoExpand() )
+            if( cr.isOverflow() )
+            {
+                if( isAutoExpand() )
+                {
+                    switch( expandedState )
+                    {
+                    case 0:
+                        autoExpand( ( int ) Math.ceil( in.remaining() * encoder.averageBytesPerChar()
) );
+                        expandedState ++;
+                        break;
+                    case 1:
+                        autoExpand( ( int ) Math.ceil( in.remaining() * encoder.maxBytesPerChar()
) );
+                        expandedState ++;
+                        break;
+                    default:
+                        throw new RuntimeException( "Expanded by " +
+                                ( int ) Math.ceil( in.remaining() * encoder.maxBytesPerChar()
) +
+                                " but that wasn't enough for '" + val + "'");
+                    }
+                    continue;
+                }
+            }
+            else
             {
-                autoExpand( limit() - position() + expectedLength );
-                continue;
+                expandedState = 0;
             }
             cr.throwException();
         }



Mime
View raw message