snuyanzin commented on code in PR #29370:
URL: https://github.com/apache/flink/pull/29370#discussion_r4167151758


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantInternalBuilder.java:
##########
@@ -185,18 +188,25 @@ public BinaryVariant build() {
     }
 
     public void appendString(String str) {
-        byte[] text = str.getBytes(StandardCharsets.UTF_8);
-        boolean longStr = text.length > MAX_SHORT_STR_SIZE;
-        checkCapacity((longStr ? 1 + U32_SIZE : 1) + text.length);
+        appendString(str.getBytes(StandardCharsets.UTF_8));
+    }
+
+    /**
+     * Appends a string given as UTF-8 bytes. The bytes are copied as they 
are, so the caller must
+     * make sure they are valid UTF-8, which the variant spec requires of 
every string.
+     */
+    public void appendString(byte[] utf8) {
+        boolean longStr = utf8.length > MAX_SHORT_STR_SIZE;
+        checkCapacity((longStr ? 1 + U32_SIZE : 1) + utf8.length);

Review Comment:
   ```suggestion
           checkCapacity((longStr ? U32_SIZE : 0) + 1+ utf8.length);
   ```
   looks like can be simplified



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to