Skip to content

Commit

Permalink
perf: remove unnecessary string allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
jwong101 committed Nov 30, 2023
1 parent b2d0f9d commit 0fba680
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions crates/forge_analyzer/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl ResolverTable {
#[inline]
fn get_default(&self, module: ModId) -> Option<DefId> {
for (defid, sym) in self.names.iter_enumerated() {
if &sym.to_string() == "default" && self.owning_module.contains(&module) {
if sym == "default" && self.owning_module.contains(&module) {
return Some(defid);
}
}
Expand Down Expand Up @@ -1261,11 +1261,9 @@ impl<'cx> FunctionAnalyzer<'cx> {
.iter()
.enumerate()
.map(|(i, arg)| {
let defid = self.res.add_anonymous(
i.to_string() + "argument",
AnonType::Unknown,
self.module,
);
let defid =
self.res
.add_anonymous(format!("{i}argument"), AnonType::Unknown, self.module);
self.lower_expr(&arg.expr, Some(defid))
})
.collect();
Expand Down Expand Up @@ -1381,8 +1379,7 @@ impl<'cx> FunctionAnalyzer<'cx> {
fn lower_jsx_child(&mut self, n: &JSXElementChild) -> Operand {
match n {
JSXElementChild::JSXText(JSXText { value, .. }) => {
let value = JsWord::from(value.to_string());
Operand::Lit(Literal::Str(value))
Operand::Lit(Literal::Str(value.clone()))
}
JSXElementChild::JSXExprContainer(JSXExprContainer { expr, .. }) => match expr {
JSXExpr::JSXEmptyExpr(_) => Operand::UNDEF,
Expand Down Expand Up @@ -2054,10 +2051,10 @@ impl Visit for FunctionCollector<'_> {

fn visit_assign_expr(&mut self, n: &AssignExpr) {
if let Some(ident) = ident_from_assign_expr(n) {
if ident.sym.to_string() == "module" {
if ident.sym == "module" {
if let Some(mem_expr) = mem_expr_from_assign(n) {
if let MemberProp::Ident(ident_property) = &mem_expr.prop {
if ident_property.sym.to_string() == "exports" {
if ident_property.sym == "exports" {
match &*n.right {
Expr::Fn(FnExpr { ident, function }) => self.handle_function(
&**&function,
Expand All @@ -2072,7 +2069,7 @@ impl Visit for FunctionCollector<'_> {
}
}
}
} else if ident.sym.to_string() == "exports" {
} else if ident.sym == "exports" {
if let Some(mem_expr) = mem_expr_from_assign(n) {
if let MemberProp::Ident(ident_property) = &mem_expr.prop {
match &*n.right {
Expand Down Expand Up @@ -2528,10 +2525,10 @@ impl Visit for Lowerer<'_> {

fn visit_assign_expr(&mut self, n: &AssignExpr) {
if let Some(ident) = ident_from_assign_expr(n) {
if ident.sym.to_string() == "module" {
if ident.sym == "module" {
if let Some(mem_expr) = mem_expr_from_assign(n) {
if let MemberProp::Ident(ident_property) = &mem_expr.prop {
if ident_property.sym.to_string() == "exports" {
if ident_property.sym == "exports" {
if let Expr::Class(ClassExpr { ident, class }) = &*n.right {
if let Some(defid) = self.res.default_export(self.curr_mod) {
self.curr_class = Some(defid);
Expand Down Expand Up @@ -2996,7 +2993,7 @@ impl Visit for ExportCollector<'_> {

fn visit_assign_expr(&mut self, n: &AssignExpr) {
if let Some(ident) = ident_from_assign_expr(n) {
if ident.sym.to_string() == "module" {
if ident.sym == "module" {
if let Some(mem_expr) = mem_expr_from_assign(n) {
if let MemberProp::Ident(ident_property) = &mem_expr.prop {
if ident_property.sym == "exports" {
Expand Down

0 comments on commit 0fba680

Please sign in to comment.