mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
perf(linter): use cow_replace instead of replace (#5643)
Related to #5586
This commit is contained in:
parent
e52d006fc8
commit
bfe9186611
1 changed files with 4 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use cow_utils::CowUtils;
|
||||
use oxc_ast::{ast::NumericLiteral, AstKind};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
|
|
@ -182,16 +183,9 @@ impl<'a> RawNum<'a> {
|
|||
}
|
||||
|
||||
impl NoLossOfPrecision {
|
||||
fn get_raw<'a>(node: &'a NumericLiteral) -> Cow<'a, str> {
|
||||
if node.raw.contains('_') {
|
||||
Cow::Owned(node.raw.replace('_', ""))
|
||||
} else {
|
||||
Cow::Borrowed(node.raw)
|
||||
}
|
||||
}
|
||||
|
||||
fn not_base_ten_loses_precision(node: &'_ NumericLiteral) -> bool {
|
||||
let raw = Self::get_raw(node).to_uppercase();
|
||||
let raw = node.raw.cow_replace('_', "");
|
||||
let raw = raw.cow_to_uppercase();
|
||||
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
|
||||
// AST always store number as f64, need a cast to format in bin/oct/hex
|
||||
let value = node.value as u64;
|
||||
|
|
@ -206,7 +200,7 @@ impl NoLossOfPrecision {
|
|||
}
|
||||
|
||||
fn base_ten_loses_precision(node: &'_ NumericLiteral) -> bool {
|
||||
let raw = Self::get_raw(node);
|
||||
let raw = node.raw.cow_replace('_', "");
|
||||
let Some(raw) = Self::normalize(&raw) else {
|
||||
return true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue