sam-1112 commented on code in PR #7746:
URL: https://github.com/apache/datafusion-comet/pull/7746#discussion_r4754360930


##########
native/spark-expr/src/static_invoke/char_varchar_utils/read_side_padding.rs:
##########
@@ -377,42 +402,32 @@ struct PadPattern<'a> {
 }
 
 impl<'a> PadPattern<'a> {
-    /// Builds a pattern that can supply up to `max_chars` padding characters.
-    fn new(pattern: &'a str, max_chars: usize) -> Self {
+    fn new(pattern: &'a str) -> Self {
         let char_offsets: Vec<usize> = pattern
             .char_indices()
             .map(|(i, _)| i)
             .chain(std::iter::once(pattern.len()))
             .collect();
-        let pattern_chars = char_offsets.len() - 1;
-        let buffer = if pattern_chars == 0 {
-            String::new()
-        } else {
-            pattern.repeat(max_chars.div_ceil(pattern_chars))
-        };
         Self {
             pattern,
             char_offsets,
-            buffer,
+            buffer: String::new(),
         }
     }
 
-    /// Returns a slice holding exactly `chars` characters of the repeating 
pattern,
-    /// or an empty slice if the pattern itself is empty. `chars` must not 
exceed the
-    /// `max_chars` the pattern was built with.
-    #[inline]
-    fn slice(&self, chars: usize) -> &str {
+    fn byte_len(&self, chars: usize) -> Option<usize> {
         let pattern_chars = self.char_offsets.len() - 1;
         if pattern_chars == 0 {
-            return "";
+            return Some(0);
         }
-        let bytes = if self.pattern.len() == pattern_chars {
-            // One byte per character (the default single space), so no offset 
lookup.
-            chars
-        } else {
-            (chars / pattern_chars) * self.pattern.len() + 
self.char_offsets[chars % pattern_chars]
-        };
-        &self.buffer[..bytes]
+        (chars / pattern_chars)
+            .checked_mul(self.pattern.len())?
+            .checked_add(self.char_offsets[chars % pattern_chars])
+    }
+

Review Comment:
   Thanks! I restore the one-byte-per-character fast path in `byte_len`, so the 
default space pattern returns `Some(chars)` without division or modulo.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to