Skip to content

Commit

Permalink
reduce allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Sep 4, 2024
1 parent d92897d commit 3ed5981
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3646,18 +3646,22 @@ fn fmt_list(arr: ArrayRef, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{value_formatter}")
}

/// writes a byte array to formatter. `[1, 2, 3]` ==> `"1,2,3"`
fn fmt_binary(data: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
let mut first = true;
for b in data {
if !first {
write!(f, ",{b}")?;
} else {
write!(f, "{}", b)?;
}
first = false;
}
Ok(())
}

impl fmt::Debug for ScalarValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_binary(data: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
data.iter()
.map(|v| format!("{v}"))
.collect::<Vec<_>>()
.join(",")
)
}
match self {
ScalarValue::Decimal128(_, _, _) => write!(f, "Decimal128({self})"),
ScalarValue::Decimal256(_, _, _) => write!(f, "Decimal256({self})"),
Expand Down

0 comments on commit 3ed5981

Please sign in to comment.