Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Commit

Permalink
Avoid moves when emitting code for String
Browse files Browse the repository at this point in the history
  • Loading branch information
xrl committed Dec 5, 2018
1 parent 3b0ae7a commit 1f6d829
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions parquet_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@ impl FieldInfo {
// TODO: can this be lumped with str by doing Borrow<str>/AsRef<str> in the
// ByteArray::from?
"String" => {
// panic!("{:#?}", self);
quote! {
{
let definition_levels : Vec<i16> = self.iter().
map(|x| x.#field_name).
map(|x| &x.#field_name).
map(|y| if y.is_some() { 1 } else { 0 }).
collect();
let vals : Vec<parquet::data_type::ByteArray> = self.iter().
map(|x| x.#field_name).
map(|x| &x.#field_name).
filter_map(|z| {
if let Some(ref inner) = z {
Some((&inner[..]).into())
Expand Down
9 changes: 8 additions & 1 deletion parquet_derive_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ struct ACompleteRecord<'a> {
pub a_string: String,
pub a_borrowed_string: &'a String,
pub maybe_a_str: Option<&'a str>,
pub maybe_a_string: Option<String>,
pub magic_number: i32,
pub low_quality_pi: f32,
pub high_quality_pi: f64,
pub maybe_pi: Option<f32>,
pub maybe_best_pi: Option<f64>,
pub borrowed_maybe_a_string: &'a Option<String>,
pub borrowed_maybe_a_str: &'a Option<&'a str>,
}

#[cfg(test)]
Expand All @@ -42,12 +44,14 @@ mod tests {
REQUIRED BINARY a_string (UTF8);
REQUIRED BINARY a_borrowed_string (UTF8);
OPTIONAL BINARY a_maybe_str (UTF8);
OPTIONAL BINARY a_maybe_string (UTF8);
REQUIRED INT32 magic_number;
REQUIRED FLOAT low_quality_pi;
REQUIRED DOUBLE high_quality_pi;
OPTIONAL FLOAT maybe_pi;
OPTIONAL DOUBLE maybe_best_pi;
OPTIONAL BINARY borrowed_maybe_a_string (UTF8);
OPTIONAL BINARY maybe_a_str (UTF8);
}";
let schema = Rc::new(parse_message_type(schema_str).unwrap());

Expand All @@ -56,20 +60,23 @@ mod tests {

let a_str = "hello mother".to_owned();
let a_borrowed_string = "cool news".to_owned();
let maybe_a_string = Some("it's true, I'm a string".into());
let maybe_a_string = Some("it's true, I'm a string".to_owned());
let maybe_a_str = Some(&a_str[..]);

let drs: Vec<ACompleteRecord> = vec![ACompleteRecord {
a_bool: true,
a_str: &a_str[..],
a_string: "hello father".into(),
a_borrowed_string: &a_borrowed_string,
maybe_a_str: Some(&a_str[..]),
maybe_a_string: Some(a_str.clone()),
magic_number: 100,
low_quality_pi: 3.14,
high_quality_pi: 3.1415,
maybe_pi: Some(3.14),
maybe_best_pi: Some(3.1415),
borrowed_maybe_a_string: &maybe_a_string,
borrowed_maybe_a_str: &maybe_a_str,
}];
let chunks = &drs[..];

Expand Down

0 comments on commit 1f6d829

Please sign in to comment.