Skip to content

Commit bfe9186

Browse files
authoredSep 9, 2024··
perf(linter): use cow_replace instead of replace (#5643)
Related to #5586
1 parent e52d006 commit bfe9186

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed
 

‎crates/oxc_linter/src/rules/eslint/no_loss_of_precision.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
22

3+
use cow_utils::CowUtils;
34
use oxc_ast::{ast::NumericLiteral, AstKind};
45
use oxc_diagnostics::OxcDiagnostic;
56
use oxc_macros::declare_oxc_lint;
@@ -182,16 +183,9 @@ impl<'a> RawNum<'a> {
182183
}
183184

184185
impl NoLossOfPrecision {
185-
fn get_raw<'a>(node: &'a NumericLiteral) -> Cow<'a, str> {
186-
if node.raw.contains('_') {
187-
Cow::Owned(node.raw.replace('_', ""))
188-
} else {
189-
Cow::Borrowed(node.raw)
190-
}
191-
}
192-
193186
fn not_base_ten_loses_precision(node: &'_ NumericLiteral) -> bool {
194-
let raw = Self::get_raw(node).to_uppercase();
187+
let raw = node.raw.cow_replace('_', "");
188+
let raw = raw.cow_to_uppercase();
195189
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
196190
// AST always store number as f64, need a cast to format in bin/oct/hex
197191
let value = node.value as u64;
@@ -206,7 +200,7 @@ impl NoLossOfPrecision {
206200
}
207201

208202
fn base_ten_loses_precision(node: &'_ NumericLiteral) -> bool {
209-
let raw = Self::get_raw(node);
203+
let raw = node.raw.cow_replace('_', "");
210204
let Some(raw) = Self::normalize(&raw) else {
211205
return true;
212206
};

0 commit comments

Comments
 (0)
Please sign in to comment.