@@ -12,6 +12,7 @@ use crate::{
1212 stream_and_get_source_and_map, stream_chunks_of_raw_source,
1313 stream_chunks_of_source_map, StreamChunks ,
1414 } ,
15+ rope:: Rope ,
1516 MapOptions , Source , SourceMap ,
1617} ;
1718
@@ -50,8 +51,6 @@ use crate::{
5051/// ```
5152pub struct CachedSource < T > {
5253 inner : Arc < T > ,
53- cached_buffer : Arc < OnceLock < Vec < u8 > > > ,
54- cached_source : Arc < OnceLock < Arc < str > > > ,
5554 cached_hash : Arc < OnceLock < u64 > > ,
5655 cached_maps :
5756 Arc < DashMap < MapOptions , Option < SourceMap > , BuildHasherDefault < FxHasher > > > ,
@@ -62,8 +61,6 @@ impl<T> CachedSource<T> {
6261 pub fn new ( inner : T ) -> Self {
6362 Self {
6463 inner : Arc :: new ( inner) ,
65- cached_buffer : Default :: default ( ) ,
66- cached_source : Default :: default ( ) ,
6764 cached_hash : Default :: default ( ) ,
6865 cached_maps : Default :: default ( ) ,
6966 }
@@ -77,17 +74,15 @@ impl<T> CachedSource<T> {
7774
7875impl < T : Source + Hash + PartialEq + Eq + ' static > Source for CachedSource < T > {
7976 fn source ( & self ) -> Cow < str > {
80- let cached = self
81- . cached_source
82- . get_or_init ( || self . inner . source ( ) . into ( ) ) ;
83- Cow :: Borrowed ( cached)
77+ self . inner . source ( )
78+ }
79+
80+ fn rope ( & self ) -> Rope < ' _ > {
81+ self . inner . rope ( )
8482 }
8583
8684 fn buffer ( & self ) -> Cow < [ u8 ] > {
87- let cached = self
88- . cached_buffer
89- . get_or_init ( || self . inner . buffer ( ) . to_vec ( ) ) ;
90- Cow :: Borrowed ( cached)
85+ self . inner . buffer ( )
9186 }
9287
9388 fn size ( & self ) -> usize {
@@ -109,7 +104,7 @@ impl<T: Source + Hash + PartialEq + Eq + 'static> Source for CachedSource<T> {
109104 }
110105}
111106
112- impl < T : Source + Hash + PartialEq + Eq + ' static > StreamChunks < ' _ >
107+ impl < T : Source + Hash + PartialEq + Eq + ' static > StreamChunks
113108 for CachedSource < T >
114109{
115110 fn stream_chunks < ' a > (
@@ -122,9 +117,7 @@ impl<T: Source + Hash + PartialEq + Eq + 'static> StreamChunks<'_>
122117 let cached_map = self . cached_maps . entry ( options. clone ( ) ) ;
123118 match cached_map {
124119 Entry :: Occupied ( entry) => {
125- let source = self
126- . cached_source
127- . get_or_init ( || self . inner . source ( ) . into ( ) ) ;
120+ let source = self . rope ( ) ;
128121 if let Some ( map) = entry. get ( ) {
129122 #[ allow( unsafe_code) ]
130123 // SAFETY: We guarantee that once a `SourceMap` is stored in the cache, it will never be removed.
@@ -162,8 +155,6 @@ impl<T> Clone for CachedSource<T> {
162155 fn clone ( & self ) -> Self {
163156 Self {
164157 inner : self . inner . clone ( ) ,
165- cached_buffer : self . cached_buffer . clone ( ) ,
166- cached_source : self . cached_source . clone ( ) ,
167158 cached_hash : self . cached_hash . clone ( ) ,
168159 cached_maps : self . cached_maps . clone ( ) ,
169160 }
@@ -196,17 +187,14 @@ impl<T: std::fmt::Debug> std::fmt::Debug for CachedSource<T> {
196187 ) -> Result < ( ) , std:: fmt:: Error > {
197188 f. debug_struct ( "CachedSource" )
198189 . field ( "inner" , self . inner . as_ref ( ) )
199- . field ( "cached_buffer" , & self . cached_buffer . get ( ) . is_some ( ) )
200- . field ( "cached_source" , & self . cached_source . get ( ) . is_some ( ) )
190+ . field ( "cached_hash" , self . cached_hash . as_ref ( ) )
201191 . field ( "cached_maps" , & ( !self . cached_maps . is_empty ( ) ) )
202192 . finish ( )
203193 }
204194}
205195
206196#[ cfg( test) ]
207197mod tests {
208- use std:: borrow:: Borrow ;
209-
210198 use crate :: {
211199 ConcatSource , OriginalSource , RawSource , ReplaceSource , SourceExt ,
212200 SourceMapSource , WithoutOriginalOptions ,
@@ -247,11 +235,6 @@ mod tests {
247235 source. size ( ) ;
248236 source. map ( & map_options) ;
249237
250- assert_eq ! ( clone. cached_source. get( ) . unwrap( ) . borrow( ) , source. source( ) ) ;
251- assert_eq ! (
252- * clone. cached_buffer. get( ) . unwrap( ) ,
253- source. buffer( ) . to_vec( )
254- ) ;
255238 assert_eq ! (
256239 * clone. cached_maps. get( & map_options) . unwrap( ) . value( ) ,
257240 source. map( & map_options)
0 commit comments