jecsand838 commented on code in PR #8242: URL: https://github.com/apache/arrow-rs/pull/8242#discussion_r2308878805
########## arrow-avro/benches/decoder.rs: ########## @@ -27,18 +27,33 @@ extern crate uuid; use apache_avro::types::Value; use apache_avro::{to_avro_datum, Decimal, Schema as ApacheSchema}; -use arrow_avro::schema::{Fingerprint, SINGLE_OBJECT_MAGIC}; +use arrow_avro::schema::{Fingerprint, FingerprintAlgorithm, CONFLUENT_MAGIC, SINGLE_OBJECT_MAGIC}; use arrow_avro::{reader::ReaderBuilder, schema::AvroSchema}; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput}; use once_cell::sync::Lazy; use std::{hint::black_box, time::Duration}; use uuid::Uuid; -fn make_prefix(fp: Fingerprint) -> [u8; 10] { - let Fingerprint::Rabin(val) = fp; - let mut buf = [0u8; 10]; - buf[..2].copy_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 - buf[2..].copy_from_slice(&val.to_le_bytes()); // little‑endian 64‑bit +fn make_prefix<const S: usize>(fp: Fingerprint) -> [u8; S] { + let mut buf = [0u8; S]; + match fp { + Fingerprint::Rabin(val) => { + buf[..2].copy_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 + buf[2..].copy_from_slice(&val.to_le_bytes()); // little‑endian 64‑bit + } + Fingerprint::SHA256(val) => { + buf[..2].copy_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 + buf[2..].copy_from_slice(&val); + } + Fingerprint::MD5(val) => { + buf[..2].copy_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 + buf[2..].copy_from_slice(&val); + } + Fingerprint::Id(id) => { + buf[..1].copy_from_slice(&CONFLUENT_MAGIC); // 00 + buf[1..].copy_from_slice(&id.to_be_bytes()); // big‑endian 32‑bit + } + } Review Comment: I'd probably drop the `const: S` here in factor of something closer to this: ```suggestion fn make_prefix(fp: Fingerprint) -> Vec<u8> { match fp { Fingerprint::Rabin(val) => { let mut buf = Vec::with_capacity(2 + 8); buf.extend_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 buf.extend_from_slice(&val.to_le_bytes()); // little-endian buf } Fingerprint::Id(id) => { let mut buf = Vec::with_capacity(1 + 4); buf.extend_from_slice(&CONFLUENT_MAGIC); // 00 buf.extend_from_slice(&id.to_be_bytes()); // big-endian buf } #[cfg(feature = "md5")] Fingerprint::MD5(val) => { let mut buf = Vec::with_capacity(2 + 16); buf.extend_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 buf.extend_from_slice(&val); buf } #[cfg(feature = "sha2")] Fingerprint::SHA256(val) => { let mut buf = Vec::with_capacity(2 + 32); buf.extend_from_slice(&SINGLE_OBJECT_MAGIC); // C3 01 buf.extend_from_slice(&val); buf } } ``` -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org