Skip to content

Commit a2dcc26

Browse files
committed
perf: use Vec to replace HashMap<i64, i64>
1 parent de65015 commit a2dcc26

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/helpers.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -996,10 +996,10 @@ pub fn stream_chunks_of_combined_source_map(
996996
let source_mapping: RefCell<HashMap<ArcStr, u32>> =
997997
RefCell::new(HashMap::default());
998998
let mut name_mapping: HashMap<ArcStr, u32> = HashMap::default();
999-
let source_index_mapping: RefCell<HashMap<i64, i64>> =
1000-
RefCell::new(HashMap::default());
1001-
let name_index_mapping: RefCell<HashMap<i64, i64>> =
1002-
RefCell::new(HashMap::default());
999+
let source_index_mapping: RefCell<Vec<i64>> =
1000+
RefCell::new(Vec::with_capacity(source_map.sources().len()));
1001+
let name_index_mapping: RefCell<Vec<i64>> =
1002+
RefCell::new(Vec::with_capacity(source_map.names().len()));
10031003
let name_index_value_mapping: RefCell<HashMap<i64, ArcStr>> =
10041004
RefCell::new(HashMap::default());
10051005
let inner_source_index: RefCell<i64> = RefCell::new(-2);
@@ -1224,7 +1224,7 @@ pub fn stream_chunks_of_combined_source_map(
12241224
if name.as_ref() == original_name {
12251225
let mut name_index_mapping = name_index_mapping.borrow_mut();
12261226
final_name_index =
1227-
name_index_mapping.get(&name_index).copied().unwrap_or(-2);
1227+
name_index_mapping.get(name_index as usize).copied().unwrap_or(-2);
12281228
if final_name_index == -2 {
12291229
if let Some(name) =
12301230
name_index_value_mapping.get(&name_index)
@@ -1240,7 +1240,7 @@ pub fn stream_chunks_of_combined_source_map(
12401240
} else {
12411241
final_name_index = -1;
12421242
}
1243-
name_index_mapping.insert(name_index, final_name_index);
1243+
name_index_mapping.insert(name_index as usize, final_name_index);
12441244
}
12451245
}
12461246
}
@@ -1276,7 +1276,7 @@ pub fn stream_chunks_of_combined_source_map(
12761276
return;
12771277
} else {
12781278
let mut source_index_mapping = source_index_mapping.borrow_mut();
1279-
if source_index_mapping.get(&source_index) == Some(&-2) {
1279+
if source_index_mapping.get(source_index as usize) == Some(&-2) {
12801280
let mut source_mapping = source_mapping.borrow_mut();
12811281
let mut global_index =
12821282
source_mapping.get(inner_source_name).copied();
@@ -1290,15 +1290,14 @@ pub fn stream_chunks_of_combined_source_map(
12901290
);
12911291
global_index = Some(len);
12921292
}
1293-
source_index_mapping
1294-
.insert(source_index, global_index.unwrap() as i64);
1293+
source_index_mapping.insert(source_index as usize, global_index.unwrap() as i64);
12951294
}
12961295
}
12971296
}
12981297

1298+
let source_index_mapping = source_index_mapping.borrow();
12991299
let final_source_index = source_index_mapping
1300-
.borrow()
1301-
.get(&source_index)
1300+
.get(source_index as usize)
13021301
.copied()
13031302
.unwrap_or(-1);
13041303
if final_source_index < 0 {
@@ -1315,7 +1314,7 @@ pub fn stream_chunks_of_combined_source_map(
13151314
// Pass through the chunk with mapping
13161315
let mut name_index_mapping = name_index_mapping.borrow_mut();
13171316
let mut final_name_index =
1318-
name_index_mapping.get(&name_index).copied().unwrap_or(-1);
1317+
name_index_mapping.get(name_index as usize).copied().unwrap_or(-1);
13191318
if final_name_index == -2 {
13201319
let name_index_value_mapping = name_index_value_mapping.borrow();
13211320
let name = name_index_value_mapping.get(&name_index).unwrap();
@@ -1327,7 +1326,7 @@ pub fn stream_chunks_of_combined_source_map(
13271326
global_index = Some(len);
13281327
}
13291328
final_name_index = global_index.unwrap() as i64;
1330-
name_index_mapping.insert(name_index, final_name_index);
1329+
name_index_mapping.insert(name_index as usize, final_name_index);
13311330
}
13321331
on_chunk(
13331332
chunk,
@@ -1356,7 +1355,7 @@ pub fn stream_chunks_of_combined_source_map(
13561355
} else {
13571356
*inner_source = source_content.clone();
13581357
}
1359-
source_index_mapping.borrow_mut().insert(i, -2);
1358+
source_index_mapping.borrow_mut().insert(i as usize, -2);
13601359
stream_chunks_of_source_map(
13611360
&source_content.unwrap(),
13621361
inner_source_map,
@@ -1446,12 +1445,12 @@ pub fn stream_chunks_of_combined_source_map(
14461445
}
14471446
source_index_mapping
14481447
.borrow_mut()
1449-
.insert(i, global_index.unwrap() as i64);
1448+
.insert(i as usize, global_index.unwrap() as i64);
14501449
}
14511450
},
14521451
&mut |i, name| {
14531452
let i = i as i64;
1454-
name_index_mapping.borrow_mut().insert(i, -2);
1453+
name_index_mapping.borrow_mut().insert(i as usize, -2);
14551454
name_index_value_mapping.borrow_mut().insert(i, name.into());
14561455
},
14571456
options,

0 commit comments

Comments
 (0)