Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c16919d3
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c16919d3
编写于
4月 02, 2013
作者:
M
Matthijs Hofstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removing mut fields from vec.rs, at_vec.rs, str.rs, unstable.rs, and cell.rs.
上级
260d74df
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
24 deletion
+22
-24
src/libcore/at_vec.rs
src/libcore/at_vec.rs
+2
-2
src/libcore/cell.rs
src/libcore/cell.rs
+5
-7
src/libcore/str.rs
src/libcore/str.rs
+2
-2
src/libcore/unstable.rs
src/libcore/unstable.rs
+7
-7
src/libcore/vec.rs
src/libcore/vec.rs
+6
-6
未找到文件。
src/libcore/at_vec.rs
浏览文件 @
c16919d3
...
...
@@ -208,7 +208,7 @@ pub mod raw {
*/
#[inline(always)]
pub
unsafe
fn
set_len
<
T
>
(
v
:
@
[
T
],
new_len
:
uint
)
{
let
repr
:
**
VecRepr
=
::
cast
::
reinterpret_cast
(
&
addr_of
(
&
v
));
let
repr
:
**
mut
VecRepr
=
::
cast
::
reinterpret_cast
(
&
addr_of
(
&
v
));
(
**
repr
)
.unboxed.fill
=
new_len
*
sys
::
size_of
::
<
T
>
();
}
...
...
@@ -226,7 +226,7 @@ pub unsafe fn push<T>(v: &mut @[T], initval: T) {
#[inline(always)]
// really pretty please
pub
unsafe
fn
push_fast
<
T
>
(
v
:
&
mut
@
[
T
],
initval
:
T
)
{
let
repr
:
**
VecRepr
=
::
cast
::
reinterpret_cast
(
&
v
);
let
repr
:
**
mut
VecRepr
=
::
cast
::
reinterpret_cast
(
&
v
);
let
fill
=
(
**
repr
)
.unboxed.fill
;
(
**
repr
)
.unboxed.fill
+=
sys
::
size_of
::
<
T
>
();
let
p
=
addr_of
(
&
((
**
repr
)
.unboxed.data
));
...
...
src/libcore/cell.rs
浏览文件 @
c16919d3
...
...
@@ -10,7 +10,7 @@
//! A mutable, nullable memory location
use
cast
::
transmute
;
use
cast
::
transmute
_mut
;
use
prelude
::
*
;
/*
...
...
@@ -20,16 +20,12 @@
*/
pub
struct
Cell
<
T
>
{
mut
value
:
Option
<
T
>
value
:
Option
<
T
>
}
impl
<
T
:
cmp
::
Eq
>
cmp
::
Eq
for
Cell
<
T
>
{
fn
eq
(
&
self
,
other
:
&
Cell
<
T
>
)
->
bool
{
unsafe
{
let
frozen_self
:
&
Option
<
T
>
=
transmute
(
&
mut
self
.value
);
let
frozen_other
:
&
Option
<
T
>
=
transmute
(
&
mut
other
.value
);
frozen_self
==
frozen_other
}
(
self
.value
)
==
(
other
.value
)
}
fn
ne
(
&
self
,
other
:
&
Cell
<
T
>
)
->
bool
{
!
self
.eq
(
other
)
}
}
...
...
@@ -46,6 +42,7 @@ pub fn empty_cell<T>() -> Cell<T> {
pub
impl
<
T
>
Cell
<
T
>
{
/// Yields the value, failing if the cell is empty.
fn
take
(
&
self
)
->
T
{
let
mut
self
=
unsafe
{
transmute_mut
(
self
)
};
if
self
.is_empty
()
{
fail
!
(
~
"attempt to take an empty cell"
);
}
...
...
@@ -57,6 +54,7 @@ fn take(&self) -> T {
/// Returns the value, failing if the cell is full.
fn
put_back
(
&
self
,
value
:
T
)
{
let
mut
self
=
unsafe
{
transmute_mut
(
self
)
};
if
!
self
.is_empty
()
{
fail
!
(
~
"attempt to put a value back into a full cell"
);
}
...
...
src/libcore/str.rs
浏览文件 @
c16919d3
...
...
@@ -2274,8 +2274,8 @@ pub unsafe fn shift_byte(s: &mut ~str) -> u8 {
/// Sets the length of the string and adds the null terminator
pub
unsafe
fn
set_len
(
v
:
&
mut
~
str
,
new_len
:
uint
)
{
let
v
:
**
vec
::
raw
::
VecRepr
=
cast
::
transmute
(
v
);
let
repr
:
*
vec
::
raw
::
VecRepr
=
*
v
;
let
v
:
**
mut
vec
::
raw
::
VecRepr
=
cast
::
transmute
(
v
);
let
repr
:
*
mut
vec
::
raw
::
VecRepr
=
*
v
;
(
*
repr
)
.unboxed.fill
=
new_len
+
1u
;
let
null
=
ptr
::
mut_offset
(
cast
::
transmute
(
&
((
*
repr
)
.unboxed.data
)),
new_len
);
...
...
src/libcore/unstable.rs
浏览文件 @
c16919d3
...
...
@@ -106,13 +106,13 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
****************************************************************************/
struct
ArcData
<
T
>
{
mut
count
:
libc
::
intptr_t
,
count
:
libc
::
intptr_t
,
// FIXME(#3224) should be able to make this non-option to save memory
mut
data
:
Option
<
T
>
,
data
:
Option
<
T
>
,
}
struct
ArcDestruct
<
T
>
{
mut
data
:
*
libc
::
c_void
,
data
:
*
libc
::
c_void
,
}
#[unsafe_destructor]
...
...
@@ -122,7 +122,7 @@ fn finalize(&self) {
do
task
::
unkillable
{
let
data
:
~
ArcData
<
T
>
=
cast
::
reinterpret_cast
(
&
self
.data
);
let
new_count
=
intrinsics
::
atomic_xsub
(
&
mut
data
.count
,
1
)
-
1
;
intrinsics
::
atomic_xsub
(
cast
::
transmute_mut
(
&
data
.count
)
,
1
)
-
1
;
assert
!
(
new_count
>=
0
);
if
new_count
==
0
{
// drop glue takes over.
...
...
@@ -186,7 +186,7 @@ pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
->
SharedMutableState
<
T
>
{
unsafe
{
let
ptr
:
~
ArcData
<
T
>
=
cast
::
reinterpret_cast
(
&
(
*
rc
)
.data
);
let
new_count
=
intrinsics
::
atomic_xadd
(
&
mut
ptr
.count
,
1
)
+
1
;
let
new_count
=
intrinsics
::
atomic_xadd
(
cast
::
transmute_mut
(
&
ptr
.count
)
,
1
)
+
1
;
assert
!
(
new_count
>=
2
);
cast
::
forget
(
ptr
);
}
...
...
@@ -252,7 +252,7 @@ fn Unlock(l: rust_little_lock) -> Unlock {
}
}
struct
ExData
<
T
>
{
lock
:
LittleLock
,
mut
failed
:
bool
,
mut
data
:
T
,
}
struct
ExData
<
T
>
{
lock
:
LittleLock
,
failed
:
bool
,
data
:
T
,
}
/**
* An arc over mutable data that is protected by a lock. For library use only.
*/
...
...
@@ -260,7 +260,7 @@ pub struct Exclusive<T> { x: SharedMutableState<ExData<T>> }
pub
fn
exclusive
<
T
:
Owned
>
(
user_data
:
T
)
->
Exclusive
<
T
>
{
let
data
=
ExData
{
lock
:
LittleLock
(),
mut
failed
:
false
,
mut
data
:
user_data
lock
:
LittleLock
(),
failed
:
false
,
data
:
user_data
};
Exclusive
{
x
:
unsafe
{
shared_mutable_state
(
data
)
}
}
}
...
...
src/libcore/vec.rs
浏览文件 @
c16919d3
...
...
@@ -633,7 +633,7 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
// This doesn't bother to make sure we have space.
#[inline(always)]
// really pretty please
unsafe
fn
push_fast
<
T
>
(
v
:
&
mut
~
[
T
],
initval
:
T
)
{
let
repr
:
**
raw
::
VecRepr
=
::
cast
::
transmute
(
v
);
let
repr
:
**
mut
raw
::
VecRepr
=
::
cast
::
transmute
(
v
);
let
fill
=
(
**
repr
)
.unboxed.fill
;
(
**
repr
)
.unboxed.fill
+=
sys
::
nonzero_size_of
::
<
T
>
();
let
p
=
addr_of
(
&
((
**
repr
)
.unboxed.data
));
...
...
@@ -2148,8 +2148,8 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
/// The internal 'unboxed' representation of a vector
pub
struct
UnboxedVecRepr
{
mut
fill
:
uint
,
mut
alloc
:
uint
,
fill
:
uint
,
alloc
:
uint
,
data
:
u8
}
...
...
@@ -2171,8 +2171,8 @@ pub struct VecRepr {
}
pub
struct
SliceRepr
{
mut
data
:
*
u8
,
mut
len
:
uint
data
:
*
u8
,
len
:
uint
}
/**
...
...
@@ -2184,7 +2184,7 @@ pub struct SliceRepr {
*/
#[inline(always)]
pub
unsafe
fn
set_len
<
T
>
(
v
:
&
mut
~
[
T
],
new_len
:
uint
)
{
let
repr
:
**
VecRepr
=
::
cast
::
transmute
(
v
);
let
repr
:
**
mut
VecRepr
=
::
cast
::
transmute
(
v
);
(
**
repr
)
.unboxed.fill
=
new_len
*
sys
::
nonzero_size_of
::
<
T
>
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录