Skip to content

Commit c317241

Browse files
committed
refactor
1 parent 36d575d commit c317241

File tree

11 files changed

+108
-149
lines changed

11 files changed

+108
-149
lines changed

src/cached_source.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
},
1414
rope::Rope,
1515
source::SourceValue,
16-
BoxSource, MapOptions, MemoryPool, Source, SourceExt, SourceMap,
16+
BoxSource, MapOptions, Source, SourceExt, SourceMap,
1717
};
1818

1919
#[derive(Default)]
@@ -122,7 +122,6 @@ impl Source for CachedSource {
122122
impl StreamChunks for CachedSource {
123123
fn stream_chunks<'a>(
124124
&'a self,
125-
memory_pool: &'a MemoryPool,
126125
options: &MapOptions,
127126
on_chunk: crate::helpers::OnChunk<'_, 'a>,
128127
on_source: crate::helpers::OnSource<'_, 'a>,
@@ -138,13 +137,7 @@ impl StreamChunks for CachedSource {
138137
let source = self.rope();
139138
if let Some(map) = map {
140139
stream_chunks_of_source_map(
141-
memory_pool,
142-
source,
143-
map,
144-
on_chunk,
145-
on_source,
146-
on_name,
147-
options,
140+
source, map, on_chunk, on_source, on_name, options,
148141
)
149142
} else {
150143
stream_chunks_of_raw_source(
@@ -154,7 +147,6 @@ impl StreamChunks for CachedSource {
154147
}
155148
None => {
156149
let (generated_info, map) = stream_and_get_source_and_map(
157-
memory_pool,
158150
&self.inner,
159151
options,
160152
on_chunk,
@@ -316,7 +308,6 @@ mod tests {
316308
let mut on_source_count = 0;
317309
let mut on_name_count = 0;
318310
let generated_info = source.stream_chunks(
319-
&MemoryPool::default(),
320311
&map_options,
321312
&mut |_chunk, _mapping| {
322313
on_chunk_count += 1;
@@ -331,7 +322,6 @@ mod tests {
331322

332323
let cached_source = CachedSource::new(source);
333324
cached_source.stream_chunks(
334-
&MemoryPool::default(),
335325
&map_options,
336326
&mut |_chunk, _mapping| {},
337327
&mut |_source_index, _source, _source_content| {},
@@ -342,7 +332,6 @@ mod tests {
342332
let mut cached_on_source_count = 0;
343333
let mut cached_on_name_count = 0;
344334
let cached_generated_info = cached_source.stream_chunks(
345-
&MemoryPool::default(),
346335
&map_options,
347336
&mut |_chunk, _mapping| {
348337
cached_on_chunk_count += 1;

src/concat_source.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{
1111
helpers::{get_map, GeneratedInfo, OnChunk, OnName, OnSource, StreamChunks},
1212
linear_map::LinearMap,
1313
source::{Mapping, OriginalLocation},
14-
BoxSource, MapOptions, MemoryPool, RawStringSource, Rope, Source, SourceExt,
15-
SourceMap, SourceValue,
14+
BoxSource, MapOptions, RawStringSource, Rope, Source, SourceExt, SourceMap,
15+
SourceValue,
1616
};
1717

1818
/// Concatenate multiple [Source]s to a single [Source].
@@ -200,7 +200,7 @@ impl Source for ConcatSource {
200200
}
201201

202202
fn map(&self, options: &MapOptions) -> Option<SourceMap> {
203-
get_map(&MemoryPool::default(), self, options)
203+
get_map(self, options)
204204
}
205205

206206
fn to_writer(&self, writer: &mut dyn std::io::Write) -> std::io::Result<()> {
@@ -230,7 +230,6 @@ impl Eq for ConcatSource {}
230230
impl StreamChunks for ConcatSource {
231231
fn stream_chunks<'a>(
232232
&'a self,
233-
memory_pool: &'a MemoryPool,
234233
options: &MapOptions,
235234
on_chunk: OnChunk<'_, 'a>,
236235
on_source: OnSource<'_, 'a>,
@@ -239,13 +238,7 @@ impl StreamChunks for ConcatSource {
239238
let children = self.optimized_children();
240239

241240
if children.len() == 1 {
242-
return children[0].stream_chunks(
243-
memory_pool,
244-
options,
245-
on_chunk,
246-
on_source,
247-
on_name,
248-
);
241+
return children[0].stream_chunks(options, on_chunk, on_source, on_name);
249242
}
250243
let mut current_line_offset = 0;
251244
let mut current_column_offset = 0;
@@ -266,7 +259,6 @@ impl StreamChunks for ConcatSource {
266259
generated_line,
267260
generated_column,
268261
} = item.stream_chunks(
269-
memory_pool,
270262
options,
271263
&mut |chunk, mapping| {
272264
let line = mapping.generated_line + current_line_offset;

src/helpers.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ use crate::{
1313
linear_map::LinearMap,
1414
source::{Mapping, OriginalLocation},
1515
with_indices::WithIndices,
16-
MapOptions, MemoryPool, Rope, SourceMap,
16+
MapOptions, Rope, SourceMap,
1717
};
1818

1919
// Adding this type because sourceContentLine not happy
20-
type InnerSourceContentLine<'context, 'text> = RefCell<
21-
LinearMap<OnceCell<Option<Vec<WithIndices<'context, 'text, Rope<'text>>>>>>,
22-
>;
20+
type InnerSourceContentLine<'text> =
21+
RefCell<LinearMap<OnceCell<Option<Vec<WithIndices<'text, Rope<'text>>>>>>>;
2322

2423
pub fn get_map<'a, S: StreamChunks>(
25-
memory_pool: &'a MemoryPool,
2624
stream: &'a S,
2725
options: &'a MapOptions,
2826
) -> Option<SourceMap> {
@@ -32,7 +30,6 @@ pub fn get_map<'a, S: StreamChunks>(
3230
let mut names: Vec<String> = Vec::new();
3331

3432
stream.stream_chunks(
35-
memory_pool,
3633
&MapOptions {
3734
columns: options.columns,
3835
final_source: true,
@@ -74,7 +71,6 @@ pub trait StreamChunks {
7471
/// [StreamChunks] abstraction
7572
fn stream_chunks<'a>(
7673
&'a self,
77-
memory_pool: &'a MemoryPool,
7874
options: &MapOptions,
7975
on_chunk: OnChunk<'_, 'a>,
8076
on_source: OnSource<'_, 'a>,
@@ -94,7 +90,6 @@ pub type OnName<'a, 'b> = &'a mut dyn FnMut(u32, Cow<'b, str>);
9490

9591
/// Default stream chunks behavior impl, see [webpack-sources streamChunks](https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/helpers/streamChunks.js#L15-L35).
9692
pub fn stream_chunks_default<'a, S>(
97-
memory_pool: &'a MemoryPool,
9893
source: S,
9994
source_map: Option<&'a SourceMap>,
10095
options: &MapOptions,
@@ -107,13 +102,7 @@ where
107102
{
108103
if let Some(map) = source_map {
109104
stream_chunks_of_source_map(
110-
memory_pool,
111-
source,
112-
map,
113-
on_chunk,
114-
on_source,
115-
on_name,
116-
options,
105+
source, map, on_chunk, on_source, on_name, options,
117106
)
118107
} else {
119108
stream_chunks_of_raw_source(source, options, on_chunk, on_source, on_name)
@@ -314,7 +303,6 @@ where
314303
}
315304

316305
pub fn stream_chunks_of_source_map<'a, S>(
317-
memory_pool: &'a MemoryPool,
318306
source: S,
319307
source_map: &'a SourceMap,
320308
on_chunk: OnChunk<'_, 'a>,
@@ -336,12 +324,7 @@ where
336324
columns: true,
337325
final_source: false,
338326
} => stream_chunks_of_source_map_full(
339-
memory_pool,
340-
source,
341-
source_map,
342-
on_chunk,
343-
on_source,
344-
on_name,
327+
source, source_map, on_chunk, on_source, on_name,
345328
),
346329
MapOptions {
347330
columns: false,
@@ -432,7 +415,6 @@ where
432415
}
433416

434417
fn stream_chunks_of_source_map_full<'a, S>(
435-
memory_pool: &'a MemoryPool,
436418
source: S,
437419
source_map: &'a SourceMap,
438420
on_chunk: OnChunk<'_, 'a>,
@@ -443,9 +425,8 @@ where
443425
S: SourceText<'a> + 'a,
444426
{
445427
let lines = split_into_lines(&source);
446-
let line_with_indices_list = lines
447-
.map(|line| WithIndices::new(memory_pool, line))
448-
.collect::<Vec<_>>();
428+
let line_with_indices_list =
429+
lines.map(|line| WithIndices::new(line)).collect::<Vec<_>>();
449430

450431
if line_with_indices_list.is_empty() {
451432
return GeneratedInfo {
@@ -732,7 +713,6 @@ type InnerSourceIndexValueMapping<'a> =
732713

733714
#[allow(clippy::too_many_arguments)]
734715
pub fn stream_chunks_of_combined_source_map<'a, S>(
735-
memory_pool: &'a MemoryPool,
736716
source: S,
737717
source_map: &'a SourceMap,
738718
inner_source_name: &'a str,
@@ -798,7 +778,6 @@ where
798778
};
799779

800780
stream_chunks_of_source_map(
801-
memory_pool,
802781
source.clone(),
803782
source_map,
804783
&mut |chunk, mapping| {
@@ -854,7 +833,7 @@ where
854833
match inner_source_contents.get(&inner_source_index) {
855834
Some(Some(source_content)) => Some(
856835
split_into_lines(source_content)
857-
.map(|line| WithIndices::new(memory_pool, line))
836+
.map(|line| WithIndices::new(line))
858837
.collect(),
859838
),
860839
_ => None,
@@ -954,7 +933,7 @@ where
954933
match inner_source_contents.get(&inner_source_index) {
955934
Some(Some(source_content)) => Some(
956935
split_into_lines(source_content)
957-
.map(|line| WithIndices::new(memory_pool, line))
936+
.map(|line| WithIndices::new(line))
958937
.collect(),
959938
),
960939
_ => None,
@@ -1119,7 +1098,6 @@ where
11191098
}
11201099
source_index_mapping.borrow_mut().insert(i, -2);
11211100
stream_chunks_of_source_map(
1122-
memory_pool,
11231101
source_content.unwrap(),
11241102
inner_source_map,
11251103
&mut |chunk, mapping| {
@@ -1217,7 +1195,6 @@ where
12171195
}
12181196

12191197
pub fn stream_and_get_source_and_map<'a, S: StreamChunks>(
1220-
memory_pool: &'a MemoryPool,
12211198
input_source: &'a S,
12221199
options: &MapOptions,
12231200
on_chunk: OnChunk<'_, 'a>,
@@ -1230,7 +1207,6 @@ pub fn stream_and_get_source_and_map<'a, S: StreamChunks>(
12301207
let mut names: Vec<String> = Vec::new();
12311208

12321209
let generated_info = input_source.stream_chunks(
1233-
memory_pool,
12341210
options,
12351211
&mut |chunk, mapping| {
12361212
mappings_encoder.encode(&mapping);

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mod with_indices;
1919
pub use cached_source::CachedSource;
2020
pub use concat_source::ConcatSource;
2121
pub use error::{Error, Result};
22-
pub use memory_pool::MemoryPool;
2322
pub use original_source::OriginalSource;
2423
pub use raw_source::{RawBufferSource, RawStringSource};
2524
pub use replace_source::{ReplaceSource, ReplacementEnforce};

0 commit comments

Comments
 (0)