Skip to content

Commit dbbf3ab

Browse files
authored
Merge pull request #32320 from ptravers/pt/9230
refactor reductionmonoid prevent clone of row on clone_from
2 parents b42e563 + 28fff25 commit dbbf3ab

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/compute/src/render/reduce.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ mod monoids {
23212321
use serde::{Deserialize, Serialize};
23222322

23232323
/// A monoid containing a single-datum row.
2324-
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Clone, Serialize, Deserialize, Hash)]
2324+
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Hash)]
23252325
pub enum ReductionMonoid {
23262326
Min(Row),
23272327
Max(Row),
@@ -2336,6 +2336,35 @@ mod monoids {
23362336
}
23372337
}
23382338

2339+
impl Clone for ReductionMonoid {
2340+
fn clone(&self) -> Self {
2341+
use ReductionMonoid::*;
2342+
match self {
2343+
Min(row) => Min(row.clone()),
2344+
Max(row) => Max(row.clone()),
2345+
}
2346+
}
2347+
2348+
fn clone_from(&mut self, source: &Self) {
2349+
use ReductionMonoid::*;
2350+
2351+
let mut row = std::mem::take(match self {
2352+
Min(row) | Max(row) => row,
2353+
});
2354+
2355+
let source_row = match source {
2356+
Min(row) | Max(row) => row,
2357+
};
2358+
2359+
row.clone_from(source_row);
2360+
2361+
match source {
2362+
Min(_) => *self = Min(row),
2363+
Max(_) => *self = Max(row),
2364+
}
2365+
}
2366+
}
2367+
23392368
impl Multiply<Diff> for ReductionMonoid {
23402369
type Output = Self;
23412370

0 commit comments

Comments
 (0)