Use Freeze for SourceFile.lines

This commit is contained in:
John Kåre Alsaker 2023-08-31 22:12:47 +02:00
parent c5996b80be
commit f49382c050
11 changed files with 199 additions and 179 deletions

View file

@ -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 {