Skip to content

Commit

Permalink
feat: remove one clone on constructing partition (#4028)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored May 24, 2024
1 parent a3a2c8d commit 0101657
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/partition/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn create_partitions_from_region_routes(
let partition = r
.region
.partition
.clone()
.as_ref()
.context(error::FindRegionRoutesSnafu {
region_id: r.region.id,
table_id,
Expand Down
14 changes: 7 additions & 7 deletions src/partition/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ impl PartitionDef {
}
}

impl TryFrom<MetaPartition> for PartitionDef {
impl TryFrom<&MetaPartition> for PartitionDef {
type Error = Error;

fn try_from(partition: MetaPartition) -> Result<Self> {
fn try_from(partition: &MetaPartition) -> Result<Self> {
let MetaPartition {
column_list,
value_list,
} = partition;

let partition_columns = column_list
.into_iter()
.map(|x| String::from_utf8_lossy(&x).to_string())
.iter()
.map(|x| String::from_utf8_lossy(x).to_string())
.collect::<Vec<String>>();

let partition_bounds = value_list
.into_iter()
.map(|x| serde_json::from_str(&String::from_utf8_lossy(&x)))
.iter()
.map(|x| serde_json::from_str(&String::from_utf8_lossy(x)))
.collect::<std::result::Result<Vec<PartitionBound>, serde_json::Error>>()
.context(error::DeserializeJsonSnafu)?;

Expand Down Expand Up @@ -197,7 +197,7 @@ mod tests {
);

// MetaPartition -> PartitionDef
let partition = MetaPartition {
let partition = &MetaPartition {
column_list: vec![b"a".to_vec(), b"b".to_vec()],
value_list: vec![
b"\"MaxValue\"".to_vec(),
Expand Down

0 comments on commit 0101657

Please sign in to comment.