Skip to content

Commit 6f86c8d

Browse files
authored
Used constant with mapping instead of write! to display scalar value bytes (#20719)
## Which issue does this PR close? - Closes #19569. ## Rationale for this change This was the latest usage as far as I can see so I've changed it. I think this is not on the hot path so if you want we can close the PR and issue with it. ## What changes are included in this PR? Instead of using write! format string write hex with using constant char mapping ## Are these changes tested? Runned debug display tests: ``` running 1 test test scalar::tests::test_binary_display ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 364 filtered out; finished in 0.00s ``` ## Are there any user-facing changes? No
1 parent 23b88fb commit 6f86c8d

File tree

1 file changed

+4
-1
lines changed
  • datafusion/common/src/scalar

1 file changed

+4
-1
lines changed

datafusion/common/src/scalar/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::cmp::Ordering;
2626
use std::collections::{HashSet, VecDeque};
2727
use std::convert::Infallible;
2828
use std::fmt;
29+
use std::fmt::Write;
2930
use std::hash::Hash;
3031
use std::hash::Hasher;
3132
use std::iter::repeat_n;
@@ -4959,8 +4960,10 @@ impl fmt::Display for ScalarValue {
49594960
| ScalarValue::BinaryView(e) => match e {
49604961
Some(bytes) => {
49614962
// print up to first 10 bytes, with trailing ... if needed
4963+
const HEX_CHARS_UPPER: &[u8; 16] = b"0123456789ABCDEF";
49624964
for b in bytes.iter().take(10) {
4963-
write!(f, "{b:02X}")?;
4965+
f.write_char(HEX_CHARS_UPPER[(b >> 4) as usize] as char)?;
4966+
f.write_char(HEX_CHARS_UPPER[(b & 0x0f) as usize] as char)?;
49644967
}
49654968
if bytes.len() > 10 {
49664969
write!(f, "...")?;

0 commit comments

Comments
 (0)