Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ac719e

Browse files
committed
ReplaceWriteCloneIntoRaw withCloneToUninit.
1 parenta4ca461 commit5ac719e

File tree

5 files changed

+11
-34
lines changed

5 files changed

+11
-34
lines changed

‎alloc/src/alloc.rs‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -424,29 +424,3 @@ pub mod __alloc_error_handler {
424424
}
425425
}
426426
}
427-
428-
#[cfg(not(no_global_oom_handling))]
429-
/// Specialize clones into pre-allocated, uninitialized memory.
430-
/// Used by `Box::clone` and `Rc`/`Arc::make_mut`.
431-
pub(crate)traitWriteCloneIntoRaw:Sized{
432-
unsafefnwrite_clone_into_raw(&self,target:*mutSelf);
433-
}
434-
435-
#[cfg(not(no_global_oom_handling))]
436-
impl<T:Clone>WriteCloneIntoRawforT{
437-
#[inline]
438-
defaultunsafefnwrite_clone_into_raw(&self,target:*mutSelf){
439-
// Having allocated *first* may allow the optimizer to create
440-
// the cloned value in-place, skipping the local and move.
441-
unsafe{ target.write(self.clone())};
442-
}
443-
}
444-
445-
#[cfg(not(no_global_oom_handling))]
446-
impl<T:Copy>WriteCloneIntoRawforT{
447-
#[inline]
448-
unsafefnwrite_clone_into_raw(&self,target:*mutSelf){
449-
// We can always copy in-place, without ever involving a local value.
450-
unsafe{ target.copy_from_nonoverlapping(self,1)};
451-
}
452-
}

‎alloc/src/boxed.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@
188188
use core::any::Any;
189189
use core::async_iter::AsyncIterator;
190190
use core::borrow;
191+
#[cfg(not(no_global_oom_handling))]
192+
use core::clone::CloneToUninit;
191193
use core::cmp::Ordering;
192194
use core::error::Error;
193195
use core::fmt;
@@ -207,7 +209,7 @@ use core::slice;
207209
use core::task::{Context,Poll};
208210

209211
#[cfg(not(no_global_oom_handling))]
210-
usecrate::alloc::{handle_alloc_error,WriteCloneIntoRaw};
212+
usecrate::alloc::handle_alloc_error;
211213
usecrate::alloc::{AllocError,Allocator,Global,Layout};
212214
#[cfg(not(no_global_oom_handling))]
213215
usecrate::borrow::Cow;
@@ -1346,7 +1348,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
13461348
// Pre-allocate memory to allow writing the cloned value directly.
13471349
letmut boxed =Self::new_uninit_in(self.1.clone());
13481350
unsafe{
1349-
(**self).write_clone_into_raw(boxed.as_mut_ptr());
1351+
(**self).clone_to_uninit(boxed.as_mut_ptr());
13501352
boxed.assume_init()
13511353
}
13521354
}

‎alloc/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#![feature(assert_matches)]
104104
#![feature(async_fn_traits)]
105105
#![feature(async_iterator)]
106+
#![feature(clone_to_uninit)]
106107
#![feature(coerce_unsized)]
107108
#![feature(const_align_of_val)]
108109
#![feature(const_box)]

‎alloc/src/rc.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ use std::boxed::Box;
249249
use core::any::Any;
250250
use core::borrow;
251251
use core::cell::Cell;
252+
#[cfg(not(no_global_oom_handling))]
253+
use core::clone::CloneToUninit;
252254
use core::cmp::Ordering;
253255
use core::fmt;
254256
use core::hash::{Hash,Hasher};
@@ -268,8 +270,6 @@ use core::slice::from_raw_parts_mut;
268270

269271
#[cfg(not(no_global_oom_handling))]
270272
usecrate::alloc::handle_alloc_error;
271-
#[cfg(not(no_global_oom_handling))]
272-
usecrate::alloc::WriteCloneIntoRaw;
273273
usecrate::alloc::{AllocError,Allocator,Global,Layout};
274274
usecrate::borrow::{Cow,ToOwned};
275275
#[cfg(not(no_global_oom_handling))]
@@ -1810,7 +1810,7 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {
18101810
letmut rc =Self::new_uninit_in(this.alloc.clone());
18111811
unsafe{
18121812
let data =Rc::get_mut_unchecked(&mut rc);
1813-
(**this).write_clone_into_raw(data.as_mut_ptr());
1813+
(**this).clone_to_uninit(data.as_mut_ptr());
18141814
*this = rc.assume_init();
18151815
}
18161816
}elseifRc::weak_count(this) !=0{

‎alloc/src/sync.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
1111
use core::any::Any;
1212
use core::borrow;
13+
#[cfg(not(no_global_oom_handling))]
14+
use core::clone::CloneToUninit;
1315
use core::cmp::Ordering;
1416
use core::fmt;
1517
use core::hash::{Hash,Hasher};
@@ -30,8 +32,6 @@ use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};
3032

3133
#[cfg(not(no_global_oom_handling))]
3234
usecrate::alloc::handle_alloc_error;
33-
#[cfg(not(no_global_oom_handling))]
34-
usecrate::alloc::WriteCloneIntoRaw;
3535
usecrate::alloc::{AllocError,Allocator,Global,Layout};
3636
usecrate::borrow::{Cow,ToOwned};
3737
usecrate::boxed::Box;
@@ -2219,7 +2219,7 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> {
22192219
letmut arc =Self::new_uninit_in(this.alloc.clone());
22202220
unsafe{
22212221
let data =Arc::get_mut_unchecked(&mut arc);
2222-
(**this).write_clone_into_raw(data.as_mut_ptr());
2222+
(**this).clone_to_uninit(data.as_mut_ptr());
22232223
*this = arc.assume_init();
22242224
}
22252225
}elseif this.inner().weak.load(Relaxed) !=1{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp