Skip to content

Commit

Permalink
fix: cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Aug 7, 2024
1 parent 0cbc461 commit 452c879
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cell::Cell;

use crate::{Allocator, Box, Vec};

/// A trait to explicitly clone an object into an arena allocator.
Expand All @@ -23,12 +25,12 @@ pub trait CloneIn<'new_alloc>: Sized {
fn clone_in(&self, alloc: &'new_alloc Allocator) -> Self::Cloned;
}

impl<'a, T, C> CloneIn<'a> for Option<T>
impl<'alloc, T, C> CloneIn<'alloc> for Option<T>
where
T: CloneIn<'a, Cloned = C>,
T: CloneIn<'alloc, Cloned = C>,
{
type Cloned = Option<C>;
fn clone_in(&self, alloc: &'a Allocator) -> Self::Cloned {
fn clone_in(&self, alloc: &'alloc Allocator) -> Self::Cloned {
self.as_ref().map(|it| it.clone_in(alloc))
}
}
Expand All @@ -53,9 +55,9 @@ where
}
}

impl<'a, T: Copy> CloneIn<'a> for std::cell::Cell<T> {
type Cloned = std::cell::Cell<T>;
fn clone_in(&self, _: &'a Allocator) -> Self::Cloned {
impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T> {
type Cloned = Cell<T>;
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
Self::Cloned::new(self.get())
}
}
Expand All @@ -70,10 +72,10 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for &'old_alloc str {
macro_rules! impl_clone_in {
($($t:ty)*) => {
$(
impl<'a> CloneIn<'a> for $t {
impl<'alloc> CloneIn<'alloc> for $t {
type Cloned = Self;
#[inline(always)]
fn clone_in(&self, _: &'a Allocator) -> Self {
fn clone_in(&self, _: &'alloc Allocator) -> Self {
*self
}
}
Expand Down

0 comments on commit 452c879

Please sign in to comment.