Skip to content

Commit 4eae42c

Browse files
committed
revert named replacement
1 parent 9826470 commit 4eae42c

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

src/replace_source.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,6 @@ impl Stream for ReplaceSourceStream<'_> {
443443
let source_content_lines: RefCell<LinearMap<Option<SourceContent>>> =
444444
RefCell::new(LinearMap::default());
445445

446-
// if has named replacements, we need to map the name to the global name index
447-
let has_named_replacements =
448-
replacements.iter().any(|repl| repl.name.is_some());
449446
let name_mapping: RefCell<HashMap<&str, u32>> =
450447
RefCell::new(HashMap::default());
451448
let name_index_mapping: RefCell<LinearMap<u32>> =
@@ -590,13 +587,9 @@ impl Stream for ReplaceSourceStream<'_> {
590587
source_index: original.source_index,
591588
original_line: original.original_line,
592589
original_column: original.original_column,
593-
name_index: if !has_named_replacements {
594-
original.name_index
595-
} else {
596-
original.name_index.and_then(|name_index| {
597-
name_index_mapping.borrow().get(&name_index).copied()
598-
})
599-
},
590+
name_index: original.name_index.and_then(|name_index| {
591+
name_index_mapping.borrow().get(&name_index).copied()
592+
}),
600593
}
601594
}),
602595
},
@@ -803,21 +796,17 @@ impl Stream for ReplaceSourceStream<'_> {
803796
on_source(source_index, source, source_content);
804797
},
805798
&mut |name_index, name| {
806-
if !has_named_replacements {
807-
on_name.borrow_mut()(name_index, name);
808-
} else {
809-
let mut name_mapping = name_mapping.borrow_mut();
810-
let mut global_index = name_mapping.get(&name).copied();
811-
if global_index.is_none() {
812-
let len = name_mapping.len() as u32;
813-
name_mapping.insert(name, len);
814-
on_name.borrow_mut()(len, name);
815-
global_index = Some(len);
816-
}
817-
name_index_mapping
818-
.borrow_mut()
819-
.insert(name_index, global_index.unwrap());
799+
let mut name_mapping = name_mapping.borrow_mut();
800+
let mut global_index = name_mapping.get(&name).copied();
801+
if global_index.is_none() {
802+
let len = name_mapping.len() as u32;
803+
name_mapping.insert(name, len);
804+
on_name.borrow_mut()(len, name);
805+
global_index = Some(len);
820806
}
807+
name_index_mapping
808+
.borrow_mut()
809+
.insert(name_index, global_index.unwrap());
821810
},
822811
);
823812

0 commit comments

Comments
 (0)