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


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -310,26 +310,12 @@ public static String lpad(String base, int len, String 
pad) {
             return "";
         }
 
-        char[] data = new char[len];
-        char[] baseChars = base.toCharArray();
-        char[] padChars = pad.toCharArray();
+        int baseEnd = endOfCodePoints(base, len);
+        int padChars = padLength(pad, len - base.codePointCount(0, baseEnd));
+        char[] data = new char[padChars + baseEnd];
 
-        // the length of the padding needed
-        int pos = Math.max(len - base.length(), 0);
-
-        // copy the padding
-        for (int i = 0; i < pos; i += pad.length()) {
-            for (int j = 0; j < pad.length() && j < pos - i; j++) {
-                data[i + j] = padChars[j];
-            }
-        }
-
-        // copy the base
-        int i = 0;
-        while (pos + i < len && i < base.length()) {
-            data[pos + i] = baseChars[i];
-            i += 1;
-        }
+        writePad(data, 0, pad, padChars);
+        base.getChars(0, baseEnd, data, padChars);

Review Comment:
   Explain please: what is the hidden reason of having this line?



-- 
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