mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
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:
1 parent
a1e7e5f13e
commit
10e9fc7f81
1 file changed
+9
-7
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user