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

perf(linter): remove unneeded memory allocation for str #4142

Merged
merged 2 commits into from
Oct 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use biome_console::markup;
use biome_css_syntax::{AnyCssDeclarationName, CssGenericProperty, CssLanguage, CssSyntaxKind};
use biome_rowan::{AstNode, Language, SyntaxNode, TextRange, WalkEvent};

fn remove_vendor_prefix(prop: &str, prefix: &str) -> String {
fn remove_vendor_prefix<'a>(prop: &'a str, prefix: &'a str) -> &'a str {
if let Some(prop) = prop.strip_prefix(prefix) {
return prop.to_string();
return prop;
}

prop.to_string()
prop
}

fn get_override_props(property: &str) -> Vec<&str> {
Expand Down Expand Up @@ -109,18 +109,16 @@ impl Visitor for NoDeclarationBlockShorthandPropertyOverridesVisitor {
let prop_lowercase = prop.to_lowercase();

let prop_prefix = vender_prefix(&prop_lowercase);
let unprefixed_prop = remove_vendor_prefix(&prop_lowercase, &prop_prefix);
let override_props = get_override_props(&unprefixed_prop);
let unprefixed_prop = remove_vendor_prefix(&prop_lowercase, prop_prefix);
let override_props = get_override_props(unprefixed_prop);

self.prior_props_in_block.iter().for_each(|prior_prop| {
let prior_prop_prefix = vender_prefix(&prior_prop.lowercase);
let unprefixed_prior_prop =
remove_vendor_prefix(&prior_prop.lowercase, &prior_prop_prefix);
remove_vendor_prefix(&prior_prop.lowercase, prior_prop_prefix);

if prop_prefix == prior_prop_prefix
&& override_props
.binary_search(&unprefixed_prior_prop.as_str())
.is_ok()
&& override_props.binary_search(&unprefixed_prior_prop).is_ok()
{
ctx.match_query(
NoDeclarationBlockShorthandPropertyOverridesQuery {
Expand Down
8 changes: 4 additions & 4 deletions crates/biome_css_analyze/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ pub fn is_custom_function(value: &str) -> bool {
}

// Returns the vendor prefix extracted from an input string.
pub fn vender_prefix(prop: &str) -> String {
pub fn vender_prefix(prop: &str) -> &str {
for prefix in VENDOR_PREFIXES.iter() {
if prop.starts_with(prefix) {
return (*prefix).to_string();
return prefix;
}
}
String::new()
""
}

pub fn is_pseudo_elements(prop: &str) -> bool {
Expand All @@ -138,7 +138,7 @@ pub fn is_pseudo_elements(prop: &str) -> bool {
|| OTHER_PSEUDO_ELEMENTS.contains(&prop)
}

/// Check if the input string is custom selector
/// Check if the input string is custom selector
/// See https://drafts.csswg.org/css-extensions/#custom-selectors for more details
pub fn is_custom_selector(prop: &str) -> bool {
prop.starts_with("--")
Expand Down