Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b3941655
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,发现更多精彩内容 >>
提交
b3941655
编写于
3月 31, 2018
作者:
S
Scott McMurray
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Deprecate offset_to; switch core&alloc to using offset_from instead
Bonus: might make code than uses `.len()` on slice iterators faster
上级
80785a54
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
13 deletion
+19
-13
src/liballoc/lib.rs
src/liballoc/lib.rs
+1
-1
src/liballoc/vec.rs
src/liballoc/vec.rs
+4
-3
src/libcore/ptr.rs
src/libcore/ptr.rs
+8
-4
src/libcore/slice/mod.rs
src/libcore/slice/mod.rs
+6
-5
未找到文件。
src/liballoc/lib.rs
浏览文件 @
b3941655
...
...
@@ -103,13 +103,13 @@
#![feature(lang_items)]
#![feature(needs_allocator)]
#![feature(nonzero)]
#![feature(offset_to)]
#![feature(optin_builtin_traits)]
#![feature(pattern)]
#![feature(pin)]
#![feature(placement_in_syntax)]
#![feature(placement_new_protocol)]
#![feature(ptr_internals)]
#![feature(ptr_offset_from)]
#![feature(rustc_attrs)]
#![feature(slice_get_slice)]
#![feature(slice_rsplit)]
...
...
src/liballoc/vec.rs
浏览文件 @
b3941655
...
...
@@ -2338,9 +2338,10 @@ fn next(&mut self) -> Option<T> {
#[inline]
fn
size_hint
(
&
self
)
->
(
usize
,
Option
<
usize
>
)
{
let
exact
=
match
self
.ptr
.offset_to
(
self
.end
)
{
Some
(
x
)
=>
x
as
usize
,
None
=>
(
self
.end
as
usize
)
.wrapping_sub
(
self
.ptr
as
usize
),
let
exact
=
if
mem
::
size_of
::
<
T
>
()
==
0
{
(
self
.end
as
usize
)
.wrapping_sub
(
self
.ptr
as
usize
)
}
else
{
unsafe
{
self
.end
.offset_from
(
self
.ptr
)
as
usize
}
};
(
exact
,
Some
(
exact
))
}
...
...
src/libcore/ptr.rs
浏览文件 @
b3941655
...
...
@@ -677,6 +677,7 @@ pub fn wrapping_offset(self, count: isize) -> *const T where T: Sized {
///
/// ```
/// #![feature(offset_to)]
/// #![allow(deprecated)]
///
/// fn main() {
/// let a = [0; 5];
...
...
@@ -689,14 +690,15 @@ pub fn wrapping_offset(self, count: isize) -> *const T where T: Sized {
/// }
/// ```
#[unstable(feature
=
"offset_to"
,
issue
=
"41079"
)]
#[rustc_deprecated(since
=
"1.27.0"
,
reason
=
"Replaced by `wrapping_offset_from`, with the
\
opposite argument order. If you're writing unsafe code, consider `offset_from`."
)]
#[inline]
pub
fn
offset_to
(
self
,
other
:
*
const
T
)
->
Option
<
isize
>
where
T
:
Sized
{
let
size
=
mem
::
size_of
::
<
T
>
();
if
size
==
0
{
None
}
else
{
let
diff
=
(
other
as
isize
)
.wrapping_sub
(
self
as
isize
);
Some
(
diff
/
size
as
isize
)
Some
(
other
.wrapping_offset_from
(
self
))
}
}
...
...
@@ -1442,6 +1444,7 @@ pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T> {
///
/// ```
/// #![feature(offset_to)]
/// #![allow(deprecated)]
///
/// fn main() {
/// let mut a = [0; 5];
...
...
@@ -1454,14 +1457,15 @@ pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T> {
/// }
/// ```
#[unstable(feature
=
"offset_to"
,
issue
=
"41079"
)]
#[rustc_deprecated(since
=
"1.27.0"
,
reason
=
"Replaced by `wrapping_offset_from`, with the
\
opposite argument order. If you're writing unsafe code, consider `offset_from`."
)]
#[inline]
pub
fn
offset_to
(
self
,
other
:
*
const
T
)
->
Option
<
isize
>
where
T
:
Sized
{
let
size
=
mem
::
size_of
::
<
T
>
();
if
size
==
0
{
None
}
else
{
let
diff
=
(
other
as
isize
)
.wrapping_sub
(
self
as
isize
);
Some
(
diff
/
size
as
isize
)
Some
(
other
.wrapping_offset_from
(
self
))
}
}
...
...
src/libcore/slice/mod.rs
浏览文件 @
b3941655
...
...
@@ -1185,7 +1185,7 @@ fn next(&mut self) -> Option<$elem> {
#[inline]
fn
size_hint
(
&
self
)
->
(
usize
,
Option
<
usize
>
)
{
let
exact
=
ptrdistance
(
self
.ptr
,
self
.end
)
;
let
exact
=
unsafe
{
ptrdistance
(
self
.ptr
,
self
.end
)
}
;
(
exact
,
Some
(
exact
))
}
...
...
@@ -1593,10 +1593,11 @@ unsafe impl<'a, T> TrustedLen for IterMut<'a, T> {}
// Return the number of elements of `T` from `start` to `end`.
// Return the arithmetic difference if `T` is zero size.
#[inline(always)]
fn
ptrdistance
<
T
>
(
start
:
*
const
T
,
end
:
*
const
T
)
->
usize
{
match
start
.offset_to
(
end
)
{
Some
(
x
)
=>
x
as
usize
,
None
=>
(
end
as
usize
)
.wrapping_sub
(
start
as
usize
),
unsafe
fn
ptrdistance
<
T
>
(
start
:
*
const
T
,
end
:
*
const
T
)
->
usize
{
if
mem
::
size_of
::
<
T
>
()
==
0
{
(
end
as
usize
)
.wrapping_sub
(
start
as
usize
)
}
else
{
end
.offset_from
(
start
)
as
usize
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录