Skip to content

Commit 2fe42e1

Browse files
committed
chore: add more rule
1 parent 1b6e1b6 commit 2fe42e1

File tree

17 files changed

+76
-51
lines changed

17 files changed

+76
-51
lines changed

Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,5 +509,35 @@ verbose_file_reads = "warn"
509509
# https://github.com/rustwasm/wasm-bindgen/issues/3944
510510
#mem_forget = "warn"
511511

512+
# performance - memory allocation optimization
513+
box_collection = "warn"
514+
redundant_allocation = "warn"
515+
redundant_clone = "warn"
516+
unnecessary_to_owned = "warn"
517+
useless_vec = "warn"
518+
519+
# performance - function parameter optimization
520+
large_enum_variant = "warn"
521+
needless_pass_by_value = "warn"
522+
trivially_copy_pass_by_ref = "warn"
523+
524+
# performance - iterator optimization
525+
extend_with_drain = "warn"
526+
iter_with_drain = "warn"
527+
manual_find = "warn"
528+
529+
# performance - string optimization
530+
string_add = "warn"
531+
string_add_assign = "warn"
532+
533+
# performance - function call optimization
534+
expect_fun_call = "warn"
535+
or_fun_call = "warn"
536+
537+
# performance - other optimizations
538+
manual_memcpy = "warn"
539+
slow_vector_initialization = "warn"
540+
suboptimal_flops = "warn"
541+
512542
[patch.crates-io]
513543
simd-adler32 = { git = "https://github.com/mcountryman/simd-adler32.git", rev = "b279034d9eb554c3e5e0af523db044f08d8297ba" }

crates/rspack/src/builder/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,12 @@ impl CompilerOptionsBuilder {
10011001
filename: (!inline).then_some(output.source_map_filename.as_str().to_string()),
10021002
module_filename_template: output_builder
10031003
.devtool_module_filename_template
1004-
.map(|t| rspack_plugin_devtool::ModuleFilenameTemplate::String(t.as_str().to_string()))
1005-
.clone(),
1004+
.map(|t| rspack_plugin_devtool::ModuleFilenameTemplate::String(t.as_str().to_string())),
10061005
append: hidden.then_some(rspack_plugin_devtool::Append::Disabled),
10071006
columns: !cheap,
10081007
fallback_module_filename_template: output_builder
10091008
.devtool_fallback_module_filename_template
1010-
.map(|t| rspack_plugin_devtool::ModuleFilenameTemplate::String(t.as_str().to_string()))
1011-
.clone(),
1009+
.map(|t| rspack_plugin_devtool::ModuleFilenameTemplate::String(t.as_str().to_string())),
10121010
module: if module_maps { true } else { !cheap },
10131011
namespace: output_builder.devtool_namespace.clone(),
10141012
no_sources,
@@ -1035,8 +1033,7 @@ impl CompilerOptionsBuilder {
10351033
let options = rspack_plugin_devtool::EvalDevToolModulePluginOptions {
10361034
module_filename_template: output_builder
10371035
.devtool_module_filename_template
1038-
.map(|t| rspack_plugin_devtool::ModuleFilenameTemplate::String(t.as_str().to_string()))
1039-
.clone(),
1036+
.map(|t| rspack_plugin_devtool::ModuleFilenameTemplate::String(t.as_str().to_string())),
10401037
namespace: output_builder.devtool_namespace.clone(),
10411038
source_url_comment: None,
10421039
};
@@ -1756,7 +1753,7 @@ impl ModuleOptionsBuilder {
17561753
named_exports: Some(true),
17571754
url: Some(true),
17581755
});
1759-
parser.insert("css".to_string(), css_parser_options.clone());
1756+
parser.insert("css".to_string(), css_parser_options);
17601757

17611758
let css_auto_parser_options = ParserOptions::CssAuto(CssAutoParserOptions {
17621759
named_exports: Some(true),

crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -958,13 +958,11 @@ impl ChunkGraph {
958958
let chunk_overhead = options.chunk_overhead.unwrap_or(10000f64);
959959
let entry_chunk_multiplicator = options.entry_chunk_multiplicator.unwrap_or(10f64);
960960
let chunk = chunk_by_ukey.expect_get(chunk_ukey);
961-
chunk_overhead
962-
+ modules_size
963-
* (if chunk.can_be_initial(chunk_group_by_ukey) {
961+
modules_size.mul_add(if chunk.can_be_initial(chunk_group_by_ukey) {
964962
entry_chunk_multiplicator
965963
} else {
966964
1f64
967-
})
965+
}, chunk_overhead)
968966
}
969967

970968
#[allow(clippy::too_many_arguments)]
@@ -998,15 +996,13 @@ impl ChunkGraph {
998996
let chunk_a = chunk_by_ukey.expect_get(chunk_a_ukey);
999997
let chunk_b = chunk_by_ukey.expect_get(chunk_b_ukey);
1000998

1001-
chunk_overhead
1002-
+ modules_size
1003-
* (if chunk_a.can_be_initial(chunk_group_by_ukey)
999+
modules_size.mul_add(if chunk_a.can_be_initial(chunk_group_by_ukey)
10041000
|| chunk_b.can_be_initial(chunk_group_by_ukey)
10051001
{
10061002
entry_chunk_multiplicator
10071003
} else {
10081004
1f64
1009-
})
1005+
}, chunk_overhead)
10101006
}
10111007

10121008
pub fn integrate_chunks(

crates/rspack_core/src/chunk_graph/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl ChunkGraph {
101101
.map(|chunk_name| format!(" <tr><td>{chunk_name}</td></tr>"))
102102
.join("\n");
103103

104-
let table_body = requests.clone();
104+
let table_body = requests;
105105

106106
format!(
107107
r#"

crates/rspack_core/src/compilation/build_module_graph/module_executor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl ModuleExecutor {
7171
};
7272
let (event_sender, event_receiver) = unbounded_channel();
7373
let (stop_sender, stop_receiver) = oneshot::channel();
74-
self.event_sender = Some(event_sender.clone());
74+
self.event_sender = Some(event_sender);
7575
self.stop_receiver = Some(stop_receiver);
7676
// avoid coop budget consumed to zero cause hang risk
7777
// related to https://tokio.rs/blog/2020-04-preemption

crates/rspack_core/src/concatenated_module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,7 +2446,7 @@ impl ConcatenatedModule {
24462446
module_graph,
24472447
module_graph_cache,
24482448
info,
2449-
export_name.clone(),
2449+
export_name,
24502450
module_to_info_map,
24512451
runtime,
24522452
as_call,
@@ -2938,7 +2938,7 @@ impl ConcatenatedModule {
29382938
mg_cache,
29392939
&ref_info.id(),
29402940
if let Some(reexport_export) = reexport.export {
2941-
[reexport_export.clone(), export_name[1..].to_vec()].concat()
2941+
[reexport_export, export_name[1..].to_vec()].concat()
29422942
} else {
29432943
export_name[1..].to_vec()
29442944
},

crates/rspack_core/src/external_module.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,15 +567,15 @@ impl ExternalModule {
567567

568568
concatenation_scope.register_namespace_import(
569569
request.primary().to_string(),
570-
attributes.clone(),
570+
attributes,
571571
format!("__rspack_external_{id}").into(),
572572
);
573573
concatenation_scope.register_namespace_export(&namespace_export_with_name);
574574
}
575575
UsedExports::UsedNamespace(false) => {
576576
concatenation_scope.register_import(
577577
request.primary().to_string(),
578-
attributes.clone(),
578+
attributes,
579579
None,
580580
);
581581
}
@@ -587,7 +587,7 @@ impl ExternalModule {
587587
"import * as __rspack_external_{} from {}{};\n",
588588
id.clone(),
589589
json_stringify(request.primary()),
590-
attributes.clone().unwrap_or_default()
590+
attributes.unwrap_or_default()
591591
),
592592
InitFragmentStage::StageESMImports,
593593
module_graph

crates/rspack_plugin_dll/src/dll_reference/dll_reference_agency_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Plugin for DllReferenceAgencyPlugin {
7070
ExternalsPlugin::new(source_type.unwrap_or("var".into()), vec![external], false).apply(ctx)?;
7171

7272
DelegatedPlugin::new(DelegatedPluginOptions {
73-
source: source.clone(),
73+
source,
7474
r#type: self.options.r#type.clone(),
7575
scope: self.options.scope.clone(),
7676
content: resolved_content,

crates/rspack_plugin_esm_library/src/chunk_link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl ExternalInterop {
144144

145145
self.default_access = Some(new_name.clone());
146146
used_names.insert(new_name.clone());
147-
new_name.clone()
147+
new_name
148148
}
149149
}
150150

@@ -171,7 +171,7 @@ impl ExternalInterop {
171171
let local_name = find_new_name(atom, used_names, &vec![]);
172172
self
173173
.property_access
174-
.insert(atom.clone(), local_name.clone());
174+
.insert(atom.clone(), local_name);
175175
self
176176
.property_access
177177
.get(atom)

crates/rspack_plugin_esm_library/src/link.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ impl EsmLibraryPlugin {
129129

130130
ctx
131131
.exported_symbols
132-
.insert(new_export.clone(), local.clone());
132+
.insert(new_export.clone(), local);
133133
already_exported_names.insert(new_export.clone());
134134
already_exported_names.get(&new_export).cloned()
135135
} else {
136136
let already_exported_names = ctx.exports.entry(local.clone()).or_default();
137-
ctx.exported_symbols.insert(exported.clone(), local.clone());
137+
ctx.exported_symbols.insert(exported.clone(), local);
138138
already_exported_names.insert(exported.clone());
139139
already_exported_names.get(&exported).cloned()
140140
}
@@ -957,10 +957,10 @@ var {} = {{}};
957957
new_name
958958
} else {
959959
all_used_names.insert(symbol.clone());
960-
symbol.clone()
960+
symbol
961961
};
962962

963-
require_info.required_symbol = Some(new_name.clone());
963+
require_info.required_symbol = Some(new_name);
964964
}
965965

966966
require_info
@@ -1048,7 +1048,7 @@ var {} = {{}};
10481048
let entry_chunk_link = link.get_mut_unwrap(&entry_chunk);
10491049
entry_chunk_link.add_re_export(
10501050
current_chunk,
1051-
exported.clone(),
1051+
exported,
10521052
"default".to_string().into(),
10531053
);
10541054
}
@@ -1608,7 +1608,7 @@ var {} = {{}};
16081608
.filter_map(|(ref_string, binding_ref)| match binding_ref {
16091609
Ref::Symbol(symbol_ref) => Some((ref_string, symbol_ref)),
16101610
Ref::Inline(inlined_string) => {
1611-
inline_refs.insert(ref_string.clone(), Ref::Inline(inlined_string));
1611+
inline_refs.insert(ref_string, Ref::Inline(inlined_string));
16121612
None
16131613
}
16141614
})
@@ -2167,7 +2167,7 @@ var {} = {{}};
21672167
mg_cache,
21682168
&ref_info.id(),
21692169
if let Some(reexport_export) = reexport.export {
2170-
[reexport_export.clone(), export_name[1..].to_vec()].concat()
2170+
[reexport_export, export_name[1..].to_vec()].concat()
21712171
} else {
21722172
export_name[1..].to_vec()
21732173
},

0 commit comments

Comments
 (0)