8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char

Brian Burkhalter brian.burkhalter at oracle.com
Thu Feb 21 18:07:23 UTC 2019


> On Feb 21, 2019, at 9:57 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
>> Updated patch below. It’s a little unclear where to put ‘pos = position()’. 
> remaining() also reads the position  so I think you want:
> 
> int pos = src.position();
> int lim = src.limit();
> int rem = (pos <= lim) ? lim - pos : 0;

Oh, your are correct but I don’t think we want “src.”.

Thanks,

Brian

+#if[char]
+
+    public $Type$Buffer put(String src, int start, int end) {
+        int length = end - start;
+        checkBounds(start, length, src.length());
+        if (isReadOnly())
+            throw new ReadOnlyBufferException();
+        int pos = position();
+        int lim = limit();
+        int rem = (pos <= lim) ? lim - pos : 0;
+        if (length > rem)
+            throw new BufferOverflowException();
+        src.getChars(start, end, hb, ix(pos));
+        position(pos + length);
+        return this;
+    }
+
+#end[char]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190221/4f75223a/attachment.html>


More information about the nio-dev mailing list