Skip to content

Commit

Permalink
Add Freeze::clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Sep 8, 2023
1 parent f49382c commit c83eba9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_data_structures/src/sync/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ impl<T> FreezeLock<T> {
}
}

/// Clones the inner value along with the frozen state.
#[inline]
pub fn clone(&self) -> Self
where
T: Clone,
{
let lock = self.read();
Self::with(lock.clone(), self.is_frozen())
}

#[inline]
pub fn is_frozen(&self) -> bool {
self.frozen.load(Ordering::Acquire)
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,16 +1367,10 @@ impl Clone for SourceFile {
name: self.name.clone(),
src: self.src.clone(),
src_hash: self.src_hash,
external_src: {
let lock = self.external_src.read();
FreezeLock::with(lock.clone(), self.external_src.is_frozen())
},
external_src: self.external_src.clone(),
start_pos: self.start_pos,
source_len: self.source_len,
lines: {
let lock = self.lines.read();
FreezeLock::with(lock.clone(), self.lines.is_frozen())
},
lines: self.lines.clone(),
multibyte_chars: self.multibyte_chars.clone(),
non_narrow_chars: self.non_narrow_chars.clone(),
normalized_pos: self.normalized_pos.clone(),
Expand Down

0 comments on commit c83eba9

Please sign in to comment.