forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This brings the `alloc` crate in-tree. The code comes from Rust 1.54.0-beta.1, i.e. commit `bf62f4de3`. Signed-off-by: Miguel Ojeda <[email protected]>
- Loading branch information
Showing
70 changed files
with
38,740 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::*; | ||
|
||
extern crate test; | ||
use crate::boxed::Box; | ||
use test::Bencher; | ||
|
||
#[test] | ||
fn allocate_zeroed() { | ||
unsafe { | ||
let layout = Layout::from_size_align(1024, 1).unwrap(); | ||
let ptr = | ||
Global.allocate_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout)); | ||
|
||
let mut i = ptr.as_non_null_ptr().as_ptr(); | ||
let end = i.add(layout.size()); | ||
while i < end { | ||
assert_eq!(*i, 0); | ||
i = i.offset(1); | ||
} | ||
Global.deallocate(ptr.as_non_null_ptr(), layout); | ||
} | ||
} | ||
|
||
#[bench] | ||
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks | ||
fn alloc_owned_small(b: &mut Bencher) { | ||
b.iter(|| { | ||
let _: Box<_> = box 10; | ||
}) | ||
} |
Oops, something went wrong.