You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "viirya (via GitHub)" <gi...@apache.org> on 2023/02/20 18:02:00 UTC

[GitHub] [arrow-rs] viirya commented on a diff in pull request #3734: replace for loop by try_for_each

viirya commented on code in PR #3734:
URL: https://github.com/apache/arrow-rs/pull/3734#discussion_r1112224836


##########
arrow-csv/src/reader/mod.rs:
##########
@@ -866,21 +866,24 @@ fn parse_decimal_with_parameter<T: DecimalType>(
         let mut negative = false;
         let mut result = T::Native::usize_as(0);
 
-        for byte in bytes[0..offset].iter().rev() {
-            match byte {
-                b'-' => {
-                    negative = true;
-                }
-                b'0'..=b'9' => {
-                    let add =
-                        T::Native::usize_as((byte - b'0') as usize).mul_checked(base)?;
-                    result = result.add_checked(add)?;
-                    base = base.mul_checked(T::Native::usize_as(10))?;
+        bytes[0..offset]
+            .iter()
+            .rev()
+            .try_for_each::<_, Result<(), ArrowError>>(|&byte| {
+                match byte {
+                    b'-' => {
+                        negative = true;
+                    }
+                    b'0'..=b'9' => {
+                        let add = T::Native::usize_as((byte - b'0') as usize)
+                            .mul_checked(base)?;
+                        result = result.add_checked(add)?;
+                        base = base.mul_checked(T::Native::usize_as(10))?;
+                    }
+                    _ => (),
                 }
-                // because of the PARSE_DECIMAL_RE, bytes just contains digit、'-' and '.'.

Review Comment:
   No need to keep the comment?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org