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

Optimize tick trimming #2689

Merged
merged 3 commits into from
Oct 20, 2023
Merged
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
8 changes: 0 additions & 8 deletions crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,3 @@ fn extension(path: &str) -> &str {
fn directory(path: &str) -> &str {
path.rsplit_once(&['/', '\\']).map_or("", |(directory, _)| directory)
}

fn trim_tick(name: &str) -> &str {
if name.as_bytes().iter().rev().nth(1) == Some(&b'`') {
&name[..name.len() - 2]
} else {
name
}
}
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,6 @@ pub fn to_ident(name: &str) -> TokenStream {
"abstract" | "as" | "become" | "box" | "break" | "const" | "continue" | "crate" | "do" | "else" | "enum" | "extern" | "false" | "final" | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match" | "mod" | "move" | "mut" | "override" | "priv" | "pub" | "ref" | "return" | "static" | "struct" | "super" | "trait" | "true" | "type" | "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" | "while" | "yield" | "try" | "async" | "await" | "dyn" => format!("r#{name}").into(),
"Self" | "self" => format!("{name}_").into(),
"_" => "unused".into(),
_ => crate::trim_tick(name).into(),
_ => name.into(),
}
}
8 changes: 0 additions & 8 deletions crates/libs/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ pub fn coded_index_size(tables: &[usize]) -> usize {
}
}

fn trim_tick(name: &str) -> &str {
if name.as_bytes().iter().rev().nth(1) == Some(&b'`') {
&name[..name.len() - 2]
} else {
name
}
}

#[derive(Debug)]
pub enum Value {
Bool(bool),
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Reader {
namespace_items.entry(field.name()).or_default().push(Item::Const(field));
}
} else {
namespace_items.entry(trim_tick(name)).or_default().push(Item::Type(def));
namespace_items.entry(name).or_default().push(Item::Type(def));

// TODO: these should all be fields on the Apis class so we don't have to go looking for all of these as well.
if def.extends() == Some(TypeName::Enum) && !def.flags().contains(TypeAttributes::WindowsRuntime) && !def.has_attribute("ScopedEnumAttribute") {
Expand Down
12 changes: 10 additions & 2 deletions crates/libs/metadata/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl TypeDef {
}

pub fn name(&self) -> &'static str {
self.str(1)
trim_tick(self.str(1))
}

pub fn namespace(&self) -> &'static str {
Expand Down Expand Up @@ -395,7 +395,7 @@ impl TypeDef {

impl TypeRef {
pub fn name(&self) -> &'static str {
self.str(1)
trim_tick(self.str(1))
}

pub fn namespace(&self) -> &'static str {
Expand All @@ -410,3 +410,11 @@ impl TypeRef {
self.decode(0)
}
}

fn trim_tick(name: &str) -> &str {
if name.as_bytes().iter().rev().nth(1) == Some(&b'`') {
&name[..name.len() - 2]
} else {
name
}
}
4 changes: 1 addition & 3 deletions crates/libs/metadata/src/type_name.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(non_upper_case_globals)]

use super::*;

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd)]
pub struct TypeName {
pub namespace: &'static str,
Expand Down Expand Up @@ -54,7 +52,7 @@ impl TypeName {
}

pub fn new(namespace: &'static str, name: &'static str) -> Self {
Self { namespace, name: trim_tick(name) }
Self { namespace, name }
}

pub fn parse(full_name: &'static str) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/standalone/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn write_no_inner_attr(output: &str, filter: &[&str]) {
}

fn riddle(output: &str, filter: &[&str], config: &[&str]) {
std::fs::remove_file(output).expect("Failed to delete output");
_ = std::fs::remove_file(output);

let mut command = std::process::Command::new("cargo");

Expand Down