mbutrovich commented on code in PR #12422:
URL: https://github.com/apache/arrow-rs/pull/12422#discussion_r4670268949
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -1965,8 +1971,14 @@ pub fn cast_with_options(
// units are never the same when the types are the same
let converted = match from_size.cmp(&to_size) {
Ordering::Greater => {
- let divisor = from_size / to_size;
- time_array.unary::<_, Int64Type>(|o| o / divisor)
+ // A constant divisor lets the compiler replace each
division with a multiply
+ // and shifts. The ratio of two time units is always one
of these three
+ match from_size / to_size {
+ 1_000 => time_array.unary::<_, Int64Type>(|o| o /
1_000),
+ 1_000_000 => time_array.unary::<_, Int64Type>(|o| o /
1_000_000),
+ 1_000_000_000 => time_array.unary::<_, Int64Type>(|o|
o / 1_000_000_000),
+ divisor => time_array.unary::<_, Int64Type>(|o| o /
divisor),
+ }
Review Comment:
I had broken this out to a function, but I ultimately accepted the code
duplication. Adding the documentation to have context for a private function
elsewhere that exists for such a specific scenario proved more trouble than it
was worth. It's already a deeply nested match structure, which I think is
actually easier to interpret for a human as a decision tree.
--
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]