lyne7-sc commented on code in PR #21891:
URL: https://github.com/apache/datafusion/pull/21891#discussion_r3201995856
##########
datafusion/functions-nested/src/range.rs:
##########
@@ -542,32 +538,57 @@ fn retrieve_range_args(
Some((start, stop, step))
}
-/// Returns an iterator of i64 values from start to stop
-fn gen_range_iter(
+/// Generate integer range values directly into the provided buffer.
+#[inline]
+fn generate_range_values(
start: i64,
stop: i64,
- decreasing: bool,
+ step: i64,
include_upper: bool,
-) -> Box<dyn Iterator<Item = i64>> {
- match (decreasing, include_upper) {
- // Decreasing range, stop is inclusive
- (true, true) => Box::new((stop..=start).rev()),
- // Decreasing range, stop is exclusive
- (true, false) => {
- if stop == i64::MAX {
- // start is never greater than stop, and stop is exclusive,
- // so the decreasing range must be empty.
- Box::new(std::iter::empty())
- } else {
- // Increase the stop value by one to exclude it.
- // Since stop is not i64::MAX, `stop + 1` will not overflow.
- Box::new((stop + 1..=start).rev())
+ values: &mut Vec<i64>,
+) {
+ if !include_upper && start == stop {
+ return;
+ }
+
+ if step > 0 {
+ let limit = if include_upper {
+ stop
+ } else {
+ stop.saturating_sub(1)
+ };
+ if start > limit {
+ return;
+ }
+ let count = ((limit - start) as u64 / step as u64 + 1) as usize;
Review Comment:
Fixed, and added regression coverage for this case.
--
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]