Use Freeze for SourceFile.lines
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::sync::{AtomicBool, ReadGuard, RwLock, WriteGuard};
|
||||
use crate::sync::{DynSend, DynSync};
|
||||
use std::{
|
||||
cell::UnsafeCell,
|
||||
intrinsics::likely,
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::atomic::Ordering,
|
||||
@@ -49,6 +50,17 @@ impl<T> FreezeLock<T> {
|
||||
self.frozen.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
/// Get the inner value if frozen.
|
||||
#[inline]
|
||||
pub fn get(&self) -> Option<&T> {
|
||||
if likely(self.frozen.load(Ordering::Acquire)) {
|
||||
// SAFETY: This is frozen so the data cannot be modified.
|
||||
unsafe { Some(&*self.data.get()) }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn read(&self) -> FreezeReadGuard<'_, T> {
|
||||
FreezeReadGuard {
|
||||
|
||||
Reference in New Issue
Block a user