Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
13815e4b
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
13815e4b
编写于
6月 08, 2020
作者:
R
Ralf Jung
提交者:
GitHub
6月 08, 2020
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #72811 - pickfire:liballoc-impl, r=Amanieu
Liballoc impl Mainly code rearrangements
上级
e1350878
71404633
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
42 deletion
+40
-42
src/liballoc/raw_vec.rs
src/liballoc/raw_vec.rs
+24
-26
src/liballoc/vec.rs
src/liballoc/vec.rs
+16
-16
未找到文件。
src/liballoc/raw_vec.rs
浏览文件 @
13815e4b
...
...
@@ -118,6 +118,30 @@ pub fn from_box(slice: Box<[T]>) -> Self {
RawVec
::
from_raw_parts
(
slice
.as_mut_ptr
(),
slice
.len
())
}
}
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
///
/// Note that this will correctly reconstitute any `cap` changes
/// that may have been performed. (See description of type for details.)
///
/// # Safety
///
/// * `len` must be greater than or equal to the most recently requested capacity, and
/// * `len` must be less than or equal to `self.capacity()`.
///
/// Note, that the requested capacity and `self.capacity()` could differ, as
/// an allocator could overallocate and return a greater memory block than requested.
pub
unsafe
fn
into_box
(
self
,
len
:
usize
)
->
Box
<
[
MaybeUninit
<
T
>
]
>
{
// Sanity-check one half of the safety requirement (we cannot check the other half).
debug_assert!
(
len
<=
self
.capacity
(),
"`len` must be smaller than or equal to `self.capacity()`"
);
let
me
=
ManuallyDrop
::
new
(
self
);
let
slice
=
slice
::
from_raw_parts_mut
(
me
.ptr
()
as
*
mut
MaybeUninit
<
T
>
,
len
);
Box
::
from_raw
(
slice
)
}
}
impl
<
T
,
A
:
AllocRef
>
RawVec
<
T
,
A
>
{
...
...
@@ -520,32 +544,6 @@ fn finish_grow<A>(
Ok
(
memory
)
}
impl
<
T
>
RawVec
<
T
,
Global
>
{
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
///
/// Note that this will correctly reconstitute any `cap` changes
/// that may have been performed. (See description of type for details.)
///
/// # Safety
///
/// * `len` must be greater than or equal to the most recently requested capacity, and
/// * `len` must be less than or equal to `self.capacity()`.
///
/// Note, that the requested capacity and `self.capacity()` could differ, as
/// an allocator could overallocate and return a greater memory block than requested.
pub
unsafe
fn
into_box
(
self
,
len
:
usize
)
->
Box
<
[
MaybeUninit
<
T
>
]
>
{
// Sanity-check one half of the safety requirement (we cannot check the other half).
debug_assert!
(
len
<=
self
.capacity
(),
"`len` must be smaller than or equal to `self.capacity()`"
);
let
me
=
ManuallyDrop
::
new
(
self
);
let
slice
=
slice
::
from_raw_parts_mut
(
me
.ptr
()
as
*
mut
MaybeUninit
<
T
>
,
len
);
Box
::
from_raw
(
slice
)
}
}
unsafe
impl
<
#[may_dangle]
T
,
A
:
AllocRef
>
Drop
for
RawVec
<
T
,
A
>
{
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
fn
drop
(
&
mut
self
)
{
...
...
src/liballoc/vec.rs
浏览文件 @
13815e4b
...
...
@@ -1905,6 +1905,22 @@ fn is_zero(&self) -> bool {
// Common trait implementations for Vec
////////////////////////////////////////////////////////////////////////////////
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
>
ops
::
Deref
for
Vec
<
T
>
{
type
Target
=
[
T
];
fn
deref
(
&
self
)
->
&
[
T
]
{
unsafe
{
slice
::
from_raw_parts
(
self
.as_ptr
(),
self
.len
)
}
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
>
ops
::
DerefMut
for
Vec
<
T
>
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
[
T
]
{
unsafe
{
slice
::
from_raw_parts_mut
(
self
.as_mut_ptr
(),
self
.len
)
}
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
:
Clone
>
Clone
for
Vec
<
T
>
{
#[cfg(not(test))]
...
...
@@ -1960,22 +1976,6 @@ fn index_mut(&mut self, index: I) -> &mut Self::Output {
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
>
ops
::
Deref
for
Vec
<
T
>
{
type
Target
=
[
T
];
fn
deref
(
&
self
)
->
&
[
T
]
{
unsafe
{
slice
::
from_raw_parts
(
self
.as_ptr
(),
self
.len
)
}
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
>
ops
::
DerefMut
for
Vec
<
T
>
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
[
T
]
{
unsafe
{
slice
::
from_raw_parts_mut
(
self
.as_mut_ptr
(),
self
.len
)
}
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
>
FromIterator
<
T
>
for
Vec
<
T
>
{
#[inline]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录