perf(parser): skip duplicate lookup for singleton import attributes (#28441)

Avoid constructing the duplicate-key map when an import attribute list
has fewer than two entries.

Validated with scoped Rust checks, full conformance, parser bindings,
allocation tracking.

AI-assisted (Codex).
This commit is contained in:
Boshen authored and GitHub committed 2026-10-30 11:36:23 +08:00
1 parent a1e7e5f13e
commit 10e9fc7f81
1 file changed
+9 -7
+9 -7
View File
@@ -387,13 +387,15 @@ impl<'a, C: Config> ParserImpl<'a, C> {
});
self.expect(Kind::RCurly);
let mut keys = FxHashMap::default();
for e in &with_entries {
let key = e.key.as_js_str();
let span = e.key.span();
if let Some(old_span) = keys.insert(key, span) {
let name = key.as_str().unwrap_or_else(|| span.source_text(self.source_text));
self.error(diagnostics::duplicate_import_attribute_key(name, old_span, span));
if with_entries.len() > 1 {
let mut keys = FxHashMap::default();
for e in &with_entries {
let key = e.key.as_js_str();
let span = e.key.span();
if let Some(old_span) = keys.insert(key, span) {
let name = key.as_str().unwrap_or_else(|| span.source_text(self.source_text));
self.error(diagnostics::duplicate_import_attribute_key(name, old_span, span));
}
}
}