< prev index next >

src/java.base/share/classes/java/nio/StringCharBuffer.java

Print this page
rev 52907 : 8234841: Enhance buffering of byte buffers
Reviewed-by: alanb, ahgross, rhalade, psandoz

@@ -41,16 +41,19 @@
         str = s;
         this.isReadOnly = true;
     }
 
     public CharBuffer slice() {
+        int pos = this.position();
+        int lim = this.limit();
+        int rem = (pos <= lim ? lim - pos : 0);
         return new StringCharBuffer(str,
                                     -1,
                                     0,
-                                    this.remaining(),
-                                    this.remaining(),
-                                    offset + this.position());
+                                    rem,
+                                    rem,
+                                    offset + pos);
     }
 
     private StringCharBuffer(CharSequence s,
                              int mark,
                              int pos,
< prev index next >