Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid unnecessary boxing of Vec<T> as it is already on the heap #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ heck = "0.3"
paste = "1.0"
toml = "0.5"
serde = { version = "1.0", features = ["derive"] }
regex = "1.10.4"


[dev-dependencies]
Expand Down
17 changes: 17 additions & 0 deletions src/render/typ.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use super::super::parse::{self, *};
use super::RenderContext;
use anyhow::Result;
use lazy_static::lazy_static;
use proc_macro2::TokenStream;
use quote::*;
use regex::Regex;

pub fn value_type_def_token(
type_def: &parse::ValueTypeDef,
Expand All @@ -23,6 +25,7 @@ pub fn value_type_def_token(
parse::ValueTypeDef::List(list_value) => {
let nullable = list_value.is_nullable;
let inner_token = value_type_def_token(&list_value.inner, schema, render_context)?;
let inner_token = strip_box(inner_token);

if nullable {
quote! { Option<Vec<#inner_token>>}
Expand Down Expand Up @@ -99,3 +102,17 @@ fn type_def_token(
};
Ok(result)
}

fn strip_box(input: TokenStream) -> TokenStream {
if let Some(captures) = BOX_REGEX.captures(&input.to_string()) {
if let Some(group) = captures.get(1) {
return group.as_str().parse().unwrap();
}
}

input
}

lazy_static! {
static ref BOX_REGEX: Regex = Regex::new(r#"^Box < (.*) >$"#).unwrap();
}