From 9d8ae1b0c39832f91c9f2eac959a2c3cb5c5526f Mon Sep 17 00:00:00 2001 From: pjulien Date: Sat, 21 May 2016 09:19:43 -0400 Subject: [PATCH 1/2] If the user passes in a {{CharBuffer}} himser, reward him by eliminating the last remaining allocation in string creation --- java/com/google/flatbuffers/FlatBufferBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/com/google/flatbuffers/FlatBufferBuilder.java b/java/com/google/flatbuffers/FlatBufferBuilder.java index deaece8cd..58189afcc 100644 --- a/java/com/google/flatbuffers/FlatBufferBuilder.java +++ b/java/com/google/flatbuffers/FlatBufferBuilder.java @@ -382,7 +382,8 @@ public class FlatBufferBuilder { dst.clear(); - CharBuffer src = CharBuffer.wrap(s); + CharBuffer src = s instanceof CharBuffer ? (CharBuffer) s : + CharBuffer.wrap(s); CoderResult result = encoder.encode(src, dst, true); if (result.isError()) { try { From 1aa3ee2170c0ab9075f4f24e61544518d5f60cda Mon Sep 17 00:00:00 2001 From: pjulien Date: Mon, 23 May 2016 16:47:41 -0400 Subject: [PATCH 2/2] Clarify documentation based on review comments --- java/com/google/flatbuffers/FlatBufferBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/com/google/flatbuffers/FlatBufferBuilder.java b/java/com/google/flatbuffers/FlatBufferBuilder.java index 58189afcc..fecb213f6 100644 --- a/java/com/google/flatbuffers/FlatBufferBuilder.java +++ b/java/com/google/flatbuffers/FlatBufferBuilder.java @@ -368,7 +368,8 @@ public class FlatBufferBuilder { /// @endcond /** - * Encode the string `s` in the buffer using UTF-8. + * Encode the string `s` in the buffer using UTF-8. If {@code s} is + * already a {@link CharBuffer}, this method is allocation free. * * @param s The string to encode. * @return The offset in the buffer where the encoded string starts.