Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
68129d29
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,发现更多精彩内容 >>
提交
68129d29
编写于
2月 13, 2014
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #12061 : pongad/rust/delorderable, r=cmr
#12057
上级
89b1686b
bf1464c4
变更
26
隐藏空白更改
内联
并排
Showing
26 changed file
with
55 addition
and
313 deletion
+55
-313
src/libarena/lib.rs
src/libarena/lib.rs
+3
-2
src/libcollections/bitv.rs
src/libcollections/bitv.rs
+2
-3
src/libcollections/ringbuf.rs
src/libcollections/ringbuf.rs
+2
-2
src/libextra/test.rs
src/libextra/test.rs
+6
-4
src/libglob/lib.rs
src/libglob/lib.rs
+2
-2
src/libnum/bigint.rs
src/libnum/bigint.rs
+10
-46
src/libnum/rational.rs
src/libnum/rational.rs
+0
-19
src/librustc/lib.rs
src/librustc/lib.rs
+2
-2
src/librustc/metadata/loader.rs
src/librustc/metadata/loader.rs
+2
-2
src/librustc/middle/check_match.rs
src/librustc/middle/check_match.rs
+2
-2
src/librustc/middle/trans/cabi_arm.rs
src/librustc/middle/trans/cabi_arm.rs
+2
-2
src/librustc/middle/trans/cabi_mips.rs
src/librustc/middle/trans/cabi_mips.rs
+3
-3
src/librustc/middle/trans/cabi_x86_64.rs
src/librustc/middle/trans/cabi_x86_64.rs
+2
-2
src/librustdoc/passes.rs
src/librustdoc/passes.rs
+2
-2
src/libstd/cmp.rs
src/libstd/cmp.rs
+2
-0
src/libstd/hashmap.rs
src/libstd/hashmap.rs
+2
-2
src/libstd/io/buffered.rs
src/libstd/io/buffered.rs
+2
-2
src/libstd/num/f32.rs
src/libstd/num/f32.rs
+0
-60
src/libstd/num/f64.rs
src/libstd/num/f64.rs
+0
-68
src/libstd/num/int_macros.rs
src/libstd/num/int_macros.rs
+0
-29
src/libstd/num/mod.rs
src/libstd/num/mod.rs
+3
-20
src/libstd/num/uint_macros.rs
src/libstd/num/uint_macros.rs
+0
-33
src/libstd/prelude.rs
src/libstd/prelude.rs
+1
-1
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+3
-3
src/test/bench/shootout-fasta.rs
src/test/bench/shootout-fasta.rs
+1
-1
src/test/bench/shootout-spectralnorm.rs
src/test/bench/shootout-spectralnorm.rs
+1
-1
未找到文件。
src/libarena/lib.rs
浏览文件 @
68129d29
...
...
@@ -33,6 +33,7 @@
use
std
::
cast
;
use
std
::
cell
::{
Cell
,
RefCell
};
use
std
::
mem
;
use
std
::
cmp
;
use
std
::
num
;
use
std
::
kinds
::
marker
;
use
std
::
rc
::
Rc
;
...
...
@@ -183,7 +184,7 @@ fn chunk_size(&self) -> uint {
// Functions for the POD part of the arena
fn
alloc_pod_grow
(
&
mut
self
,
n_bytes
:
uint
,
align
:
uint
)
->
*
u8
{
// Allocate a new chunk.
let
new_min_chunk_size
=
num
::
max
(
n_bytes
,
self
.chunk_size
());
let
new_min_chunk_size
=
cmp
::
max
(
n_bytes
,
self
.chunk_size
());
self
.chunks
.set
(
@
Cons
(
self
.pod_head
.clone
(),
self
.chunks
.get
()));
self
.pod_head
=
chunk
(
num
::
next_power_of_two
(
new_min_chunk_size
+
1u
),
true
);
...
...
@@ -223,7 +224,7 @@ fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
fn
alloc_nonpod_grow
(
&
mut
self
,
n_bytes
:
uint
,
align
:
uint
)
->
(
*
u8
,
*
u8
)
{
// Allocate a new chunk.
let
new_min_chunk_size
=
num
::
max
(
n_bytes
,
self
.chunk_size
());
let
new_min_chunk_size
=
cmp
::
max
(
n_bytes
,
self
.chunk_size
());
self
.chunks
.set
(
@
Cons
(
self
.head
.clone
(),
self
.chunks
.get
()));
self
.head
=
chunk
(
num
::
next_power_of_two
(
new_min_chunk_size
+
1u
),
false
);
...
...
src/libcollections/bitv.rs
浏览文件 @
68129d29
...
...
@@ -14,7 +14,6 @@
use
std
::
cmp
;
use
std
::
iter
::
RandomAccessIterator
;
use
std
::
iter
::{
Rev
,
Enumerate
,
Repeat
,
Map
,
Zip
};
use
std
::
num
;
use
std
::
ops
;
use
std
::
uint
;
use
std
::
vec
;
...
...
@@ -846,7 +845,7 @@ fn insert(&mut self, value: uint) -> bool {
}
let
nbits
=
self
.capacity
();
if
value
>=
nbits
{
let
newsize
=
num
::
max
(
value
,
nbits
*
2
)
/
uint
::
BITS
+
1
;
let
newsize
=
cmp
::
max
(
value
,
nbits
*
2
)
/
uint
::
BITS
+
1
;
assert
!
(
newsize
>
self
.bitv.storage
.len
());
self
.bitv.storage
.grow
(
newsize
,
&
0
);
}
...
...
@@ -881,7 +880,7 @@ impl BitvSet {
fn
commons
<
'a
>
(
&
'a
self
,
other
:
&
'a
BitvSet
)
->
Map
<
'static
,
((
uint
,
&
'a
uint
),
&
'a
~
[
uint
]),
(
uint
,
uint
,
uint
),
Zip
<
Enumerate
<
vec
::
Items
<
'a
,
uint
>>
,
Repeat
<&
'a
~
[
uint
]
>>>
{
let
min
=
num
::
min
(
self
.bitv.storage
.len
(),
other
.bitv.storage
.len
());
let
min
=
cmp
::
min
(
self
.bitv.storage
.len
(),
other
.bitv.storage
.len
());
self
.bitv.storage
.slice
(
0
,
min
)
.iter
()
.enumerate
()
.zip
(
Repeat
::
new
(
&
other
.bitv.storage
))
.map
(|((
i
,
&
w
),
o_store
)|
(
i
*
uint
::
BITS
,
w
,
o_store
[
i
]))
...
...
src/libcollections/ringbuf.rs
浏览文件 @
68129d29
...
...
@@ -13,7 +13,7 @@
//! RingBuf implements the trait Deque. It should be imported with `use
//! extra::container::Deque`.
use
std
::
num
;
use
std
::
cmp
;
use
std
::
vec
;
use
std
::
iter
::{
Rev
,
RandomAccessIterator
};
...
...
@@ -120,7 +120,7 @@ pub fn new() -> RingBuf<T> {
/// Create an empty RingBuf with space for at least `n` elements.
pub
fn
with_capacity
(
n
:
uint
)
->
RingBuf
<
T
>
{
RingBuf
{
nelts
:
0
,
lo
:
0
,
elts
:
vec
::
from_fn
(
num
::
max
(
MINIMUM_CAPACITY
,
n
),
|
_
|
None
)}
elts
:
vec
::
from_fn
(
cmp
::
max
(
MINIMUM_CAPACITY
,
n
),
|
_
|
None
)}
}
/// Retrieve an element in the RingBuf by index
...
...
src/libextra/test.rs
浏览文件 @
68129d29
...
...
@@ -27,6 +27,7 @@
use
collections
::
TreeMap
;
use
std
::
clone
::
Clone
;
use
std
::
cmp
;
use
std
::
io
;
use
std
::
io
::
File
;
use
std
::
io
::
Writer
;
...
...
@@ -1003,7 +1004,7 @@ pub fn compare_to_old(&self, old: &MetricMap,
if
delta
.abs
()
<=
noise
{
LikelyNoise
}
else
{
let
pct
=
delta
.abs
()
/
(
vold
.value
)
.max
(
&
f64
::
EPSILON
)
*
100.0
;
let
pct
=
delta
.abs
()
/
cmp
::
max
(
vold
.value
,
f64
::
EPSILON
)
*
100.0
;
if
vold
.noise
<
0.0
{
// When 'noise' is negative, it means we want
// to see deltas that go up over time, and can
...
...
@@ -1126,7 +1127,7 @@ pub fn ns_per_iter(&mut self) -> u64 {
if
self
.iterations
==
0
{
0
}
else
{
self
.ns_elapsed
()
/
self
.iterations
.max
(
&
1
)
self
.ns_elapsed
()
/
cmp
::
max
(
self
.iterations
,
1
)
}
}
...
...
@@ -1149,7 +1150,7 @@ pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary {
if
self
.ns_per_iter
()
==
0
{
n
=
1_000_000
;
}
else
{
n
=
1_000_000
/
self
.ns_per_iter
()
.max
(
&
1
);
n
=
1_000_000
/
cmp
::
max
(
self
.ns_per_iter
(),
1
);
}
// if the first run took more than 1ms we don't want to just
// be left doing 0 iterations on every loop. The unfortunate
...
...
@@ -1215,6 +1216,7 @@ pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary {
}
pub
mod
bench
{
use
std
::
cmp
;
use
test
::{
BenchHarness
,
BenchSamples
};
pub
fn
benchmark
(
f
:
|
&
mut
BenchHarness
|)
->
BenchSamples
{
...
...
@@ -1227,7 +1229,7 @@ pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
let
ns_iter_summ
=
bs
.auto_bench
(
f
);
let
ns_iter
=
(
ns_iter_summ
.median
as
u64
)
.max
(
&
1
);
let
ns_iter
=
cmp
::
max
(
ns_iter_summ
.median
as
u64
,
1
);
let
iter_s
=
1_000_000_000
/
ns_iter
;
let
mb_s
=
(
bs
.bytes
*
iter_s
)
/
1_000_000
;
...
...
src/libglob/lib.rs
浏览文件 @
68129d29
...
...
@@ -29,7 +29,7 @@
#[license
=
"MIT/ASL2"
]
;
use
std
::
cell
::
Cell
;
use
std
::{
os
,
path
};
use
std
::{
cmp
,
os
,
path
};
use
std
::
io
::
fs
;
use
std
::
path
::
is_sep
;
...
...
@@ -106,7 +106,7 @@ fn check_windows_verbatim(_: &Path) -> bool { false }
}
let
root_len
=
pat_root
.map_or
(
0u
,
|
p
|
p
.as_vec
()
.len
());
let
dir_patterns
=
pattern
.slice_from
(
root_len
.min
(
&
pattern
.len
()))
let
dir_patterns
=
pattern
.slice_from
(
cmp
::
min
(
root_len
,
pattern
.len
()))
.split_terminator
(
is_sep
)
.map
(|
s
|
Pattern
::
new
(
s
))
.to_owned_vec
();
let
todo
=
list_dir_sorted
(
&
root
)
.move_iter
()
.map
(|
x
|(
x
,
0u
))
.to_owned_vec
();
...
...
src/libnum/bigint.rs
浏览文件 @
68129d29
...
...
@@ -16,9 +16,9 @@
A `BigInt` is a combination of `BigUint` and `Sign`.
*/
use
std
::
cmp
;
use
std
::
cmp
::{
Eq
,
Ord
,
TotalEq
,
TotalOrd
,
Ordering
,
Less
,
Equal
,
Greater
};
use
std
::
num
;
use
std
::
num
::{
Zero
,
One
,
ToStrRadix
,
FromStrRadix
,
Orderable
};
use
std
::
num
::{
Zero
,
One
,
ToStrRadix
,
FromStrRadix
};
use
std
::
num
::{
Bitwise
,
ToPrimitive
,
FromPrimitive
};
use
std
::
rand
::
Rng
;
use
std
::
str
;
...
...
@@ -133,27 +133,9 @@ fn from_str(s: &str) -> Option<BigUint> {
impl
Num
for
BigUint
{}
impl
Orderable
for
BigUint
{
#[inline]
fn
min
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
if
self
<
other
{
self
.clone
()
}
else
{
other
.clone
()
}
}
#[inline]
fn
max
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
if
self
>
other
{
self
.clone
()
}
else
{
other
.clone
()
}
}
#[inline]
fn
clamp
(
&
self
,
mn
:
&
BigUint
,
mx
:
&
BigUint
)
->
BigUint
{
if
self
>
mx
{
mx
.clone
()
}
else
if
self
<
mn
{
mn
.clone
()
}
else
{
self
.clone
()
}
}
}
impl
BitAnd
<
BigUint
,
BigUint
>
for
BigUint
{
fn
bitand
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
let
new_len
=
num
::
min
(
self
.data
.len
(),
other
.data
.len
());
let
new_len
=
cmp
::
min
(
self
.data
.len
(),
other
.data
.len
());
let
anded
=
vec
::
from_fn
(
new_len
,
|
i
|
{
// i will never be less than the size of either data vector
let
ai
=
self
.data
[
i
];
...
...
@@ -166,7 +148,7 @@ fn bitand(&self, other: &BigUint) -> BigUint {
impl
BitOr
<
BigUint
,
BigUint
>
for
BigUint
{
fn
bitor
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
let
new_len
=
num
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
new_len
=
cmp
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
ored
=
vec
::
from_fn
(
new_len
,
|
i
|
{
let
ai
=
if
i
<
self
.data
.len
()
{
self
.data
[
i
]
}
else
{
0
};
let
bi
=
if
i
<
other
.data
.len
()
{
other
.data
[
i
]
}
else
{
0
};
...
...
@@ -178,7 +160,7 @@ fn bitor(&self, other: &BigUint) -> BigUint {
impl
BitXor
<
BigUint
,
BigUint
>
for
BigUint
{
fn
bitxor
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
let
new_len
=
num
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
new_len
=
cmp
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
xored
=
vec
::
from_fn
(
new_len
,
|
i
|
{
let
ai
=
if
i
<
self
.data
.len
()
{
self
.data
[
i
]
}
else
{
0
};
let
bi
=
if
i
<
other
.data
.len
()
{
other
.data
[
i
]
}
else
{
0
};
...
...
@@ -223,7 +205,7 @@ impl Unsigned for BigUint {}
impl
Add
<
BigUint
,
BigUint
>
for
BigUint
{
fn
add
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
let
new_len
=
num
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
new_len
=
cmp
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
mut
carry
=
0
;
let
mut
sum
=
vec
::
from_fn
(
new_len
,
|
i
|
{
...
...
@@ -242,7 +224,7 @@ fn add(&self, other: &BigUint) -> BigUint {
impl
Sub
<
BigUint
,
BigUint
>
for
BigUint
{
fn
sub
(
&
self
,
other
:
&
BigUint
)
->
BigUint
{
let
new_len
=
num
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
new_len
=
cmp
::
max
(
self
.data
.len
(),
other
.data
.len
());
let
mut
borrow
=
0
;
let
diff
=
vec
::
from_fn
(
new_len
,
|
i
|
{
...
...
@@ -278,7 +260,7 @@ fn mul(&self, other: &BigUint) -> BigUint {
// = a1*b1 * base^2 +
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
// a0*b0
let
half_len
=
num
::
max
(
s_len
,
o_len
)
/
2
;
let
half_len
=
cmp
::
max
(
s_len
,
o_len
)
/
2
;
let
(
sHi
,
sLo
)
=
cut_at
(
self
,
half_len
);
let
(
oHi
,
oLo
)
=
cut_at
(
other
,
half_len
);
...
...
@@ -315,7 +297,7 @@ fn mul_digit(a: &BigUint, n: BigDigit) -> BigUint {
#[inline]
fn
cut_at
(
a
:
&
BigUint
,
n
:
uint
)
->
(
BigUint
,
BigUint
)
{
let
mid
=
num
::
min
(
a
.data
.len
(),
n
);
let
mid
=
cmp
::
min
(
a
.data
.len
(),
n
);
return
(
BigUint
::
from_slice
(
a
.data
.slice
(
mid
,
a
.data
.len
())),
BigUint
::
from_slice
(
a
.data
.slice
(
0
,
mid
)));
}
...
...
@@ -720,7 +702,7 @@ pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<BigUint> {
let
mut
n
:
BigUint
=
Zero
::
zero
();
let
mut
power
:
BigUint
=
One
::
one
();
loop
{
let
start
=
num
::
max
(
end
,
unit_len
)
-
unit_len
;
let
start
=
cmp
::
max
(
end
,
unit_len
)
-
unit_len
;
match
uint
::
parse_bytes
(
buf
.slice
(
start
,
end
),
radix
)
{
Some
(
d
)
=>
{
let
d
:
Option
<
BigUint
>
=
FromPrimitive
::
from_uint
(
d
);
...
...
@@ -941,24 +923,6 @@ fn from_str(s: &str) -> Option<BigInt> {
impl
Num
for
BigInt
{}
impl
Orderable
for
BigInt
{
#[inline]
fn
min
(
&
self
,
other
:
&
BigInt
)
->
BigInt
{
if
self
<
other
{
self
.clone
()
}
else
{
other
.clone
()
}
}
#[inline]
fn
max
(
&
self
,
other
:
&
BigInt
)
->
BigInt
{
if
self
>
other
{
self
.clone
()
}
else
{
other
.clone
()
}
}
#[inline]
fn
clamp
(
&
self
,
mn
:
&
BigInt
,
mx
:
&
BigInt
)
->
BigInt
{
if
self
>
mx
{
mx
.clone
()
}
else
if
self
<
mn
{
mn
.clone
()
}
else
{
self
.clone
()
}
}
}
impl
Shl
<
uint
,
BigInt
>
for
BigInt
{
#[inline]
fn
shl
(
&
self
,
rhs
:
&
uint
)
->
BigInt
{
...
...
src/libnum/rational.rs
浏览文件 @
68129d29
...
...
@@ -160,25 +160,6 @@ fn $method(&self, other: &Ratio<T>) -> $res {
cmp_impl!
(
impl
Ord
,
lt
,
gt
,
le
,
ge
)
cmp_impl!
(
impl
TotalOrd
,
cmp
->
cmp
::
Ordering
)
impl
<
T
:
Clone
+
Integer
+
Ord
>
Orderable
for
Ratio
<
T
>
{
#[inline]
fn
min
(
&
self
,
other
:
&
Ratio
<
T
>
)
->
Ratio
<
T
>
{
if
*
self
<
*
other
{
self
.clone
()
}
else
{
other
.clone
()
}
}
#[inline]
fn
max
(
&
self
,
other
:
&
Ratio
<
T
>
)
->
Ratio
<
T
>
{
if
*
self
>
*
other
{
self
.clone
()
}
else
{
other
.clone
()
}
}
#[inline]
fn
clamp
(
&
self
,
mn
:
&
Ratio
<
T
>
,
mx
:
&
Ratio
<
T
>
)
->
Ratio
<
T
>
{
if
*
self
>
*
mx
{
mx
.clone
()}
else
if
*
self
<
*
mn
{
mn
.clone
()
}
else
{
self
.clone
()
}
}
}
/* Arithmetic */
// a/b * c/d = (a*c)/(b*d)
impl
<
T
:
Clone
+
Integer
+
Ord
>
...
...
src/librustc/lib.rs
浏览文件 @
68129d29
...
...
@@ -46,8 +46,8 @@
use
d
=
driver
::
driver
;
use
std
::
cmp
;
use
std
::
io
;
use
std
::
num
;
use
std
::
os
;
use
std
::
str
;
use
std
::
task
;
...
...
@@ -164,7 +164,7 @@ pub fn describe_warnings() {
let
mut
max_key
=
0
;
for
&
(
_
,
name
)
in
lint_dict
.iter
()
{
max_key
=
num
::
max
(
name
.len
(),
max_key
);
max_key
=
cmp
::
max
(
name
.len
(),
max_key
);
}
fn
padded
(
max
:
uint
,
s
:
&
str
)
->
~
str
{
" "
.repeat
(
max
-
s
.len
())
+
s
...
...
src/librustc/metadata/loader.rs
浏览文件 @
68129d29
...
...
@@ -26,8 +26,8 @@
use
std
::
c_str
::
ToCStr
;
use
std
::
cast
;
use
std
::
cmp
;
use
std
::
io
;
use
std
::
num
;
use
std
::
option
;
use
std
::
os
::
consts
::{
macos
,
freebsd
,
linux
,
android
,
win32
};
use
std
::
str
;
...
...
@@ -331,7 +331,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Option<MetadataBlob> {
let
vlen
=
encoder
::
metadata_encoding_version
.len
();
debug!
(
"checking {} bytes of metadata-version stamp"
,
vlen
);
let
minsz
=
num
::
min
(
vlen
,
csz
);
let
minsz
=
cmp
::
min
(
vlen
,
csz
);
let
mut
version_ok
=
false
;
vec
::
raw
::
buf_as_slice
(
cvbuf
,
minsz
,
|
buf0
|
{
version_ok
=
(
buf0
==
...
...
src/librustc/middle/check_match.rs
浏览文件 @
68129d29
...
...
@@ -18,8 +18,8 @@
use
middle
::
moves
;
use
util
::
ppaux
::
ty_to_str
;
use
std
::
cmp
;
use
std
::
iter
;
use
std
::
num
;
use
std
::
vec
;
use
syntax
::
ast
::
*
;
use
syntax
::
ast_util
::{
unguarded_pat
,
walk_pat
};
...
...
@@ -286,7 +286,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
let
max_len
=
m
.rev_iter
()
.fold
(
0
,
|
max_len
,
r
|
{
match
r
[
0
]
.node
{
PatVec
(
ref
before
,
_
,
ref
after
)
=>
{
num
::
max
(
before
.len
()
+
after
.len
(),
max_len
)
cmp
::
max
(
before
.len
()
+
after
.len
(),
max_len
)
}
_
=>
max_len
}
...
...
src/librustc/middle/trans/cabi_arm.rs
浏览文件 @
68129d29
...
...
@@ -17,7 +17,7 @@
use
middle
::
trans
::
type_
::
Type
;
use
std
::
num
;
use
std
::
cmp
;
use
std
::
option
::{
None
,
Some
};
fn
align_up_to
(
off
:
uint
,
a
:
uint
)
->
uint
{
...
...
@@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
1
}
else
{
let
str_tys
=
ty
.field_types
();
str_tys
.iter
()
.fold
(
1
,
|
a
,
t
|
num
::
max
(
a
,
ty_align
(
*
t
)))
str_tys
.iter
()
.fold
(
1
,
|
a
,
t
|
cmp
::
max
(
a
,
ty_align
(
*
t
)))
}
}
Array
=>
{
...
...
src/librustc/middle/trans/cabi_mips.rs
浏览文件 @
68129d29
...
...
@@ -11,7 +11,7 @@
#[allow(non_uppercase_pattern_statics)]
;
use
std
::
libc
::
c_uint
;
use
std
::
num
;
use
std
::
cmp
;
use
lib
::
llvm
::{
llvm
,
Integer
,
Pointer
,
Float
,
Double
,
Struct
,
Array
};
use
lib
::
llvm
::
StructRetAttribute
;
use
middle
::
trans
::
context
::
CrateContext
;
...
...
@@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
1
}
else
{
let
str_tys
=
ty
.field_types
();
str_tys
.iter
()
.fold
(
1
,
|
a
,
t
|
num
::
max
(
a
,
ty_align
(
*
t
)))
str_tys
.iter
()
.fold
(
1
,
|
a
,
t
|
cmp
::
max
(
a
,
ty_align
(
*
t
)))
}
}
Array
=>
{
...
...
@@ -98,7 +98,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> ArgType {
let
size
=
ty_size
(
ty
)
*
8
;
let
mut
align
=
ty_align
(
ty
);
align
=
num
::
min
(
num
::
max
(
align
,
4
),
8
);
align
=
cmp
::
min
(
cmp
::
max
(
align
,
4
),
8
);
*
offset
=
align_up_to
(
*
offset
,
align
);
*
offset
+=
align_up_to
(
size
,
align
*
8
)
/
8
;
...
...
src/librustc/middle/trans/cabi_x86_64.rs
浏览文件 @
68129d29
...
...
@@ -21,7 +21,7 @@
use
middle
::
trans
::
type_
::
Type
;
use
std
::
num
;
use
std
::
cmp
;
use
std
::
vec
;
#[deriving(Clone,
Eq)]
...
...
@@ -105,7 +105,7 @@ fn ty_align(ty: Type) -> uint {
1
}
else
{
let
str_tys
=
ty
.field_types
();
str_tys
.iter
()
.fold
(
1
,
|
a
,
t
|
num
::
max
(
a
,
ty_align
(
*
t
)))
str_tys
.iter
()
.fold
(
1
,
|
a
,
t
|
cmp
::
max
(
a
,
ty_align
(
*
t
)))
}
}
Array
=>
{
...
...
src/librustdoc/passes.rs
浏览文件 @
68129d29
...
...
@@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
std
::
cmp
;
use
std
::
hashmap
::
HashSet
;
use
std
::
local_data
;
use
std
::
num
;
use
std
::
uint
;
use
syntax
::
ast
;
...
...
@@ -267,7 +267,7 @@ pub fn unindent(s: &str) -> ~str {
false
}
});
num
::
min
(
min_indent
,
spaces
)
cmp
::
min
(
min_indent
,
spaces
)
}
});
...
...
src/libstd/cmp.rs
浏览文件 @
68129d29
...
...
@@ -169,6 +169,8 @@ fn le(&self, other: &Self) -> bool { !other.lt(self) }
fn
gt
(
&
self
,
other
:
&
Self
)
->
bool
{
other
.lt
(
self
)
}
#[inline]
fn
ge
(
&
self
,
other
:
&
Self
)
->
bool
{
!
self
.lt
(
other
)
}
// FIXME (#12068): Add min/max/clamp default methods
}
/// The equivalence relation. Two values may be equivalent even if they are
...
...
src/libstd/hashmap.rs
浏览文件 @
68129d29
...
...
@@ -54,7 +54,7 @@
use
container
::{
Container
,
Mutable
,
Map
,
MutableMap
,
Set
,
MutableSet
};
use
clone
::
Clone
;
use
cmp
::{
Eq
,
Equiv
};
use
cmp
::{
Eq
,
Equiv
,
max
};
use
default
::
Default
;
#[cfg(not(stage0))]
use
fmt
;
use
hash
::
Hash
;
...
...
@@ -376,7 +376,7 @@ pub fn with_capacity(capacity: uint) -> HashMap<K, V> {
/// cause many collisions and very poor performance. Setting them
/// manually using this function can expose a DoS attack vector.
pub
fn
with_capacity_and_keys
(
k0
:
u64
,
k1
:
u64
,
capacity
:
uint
)
->
HashMap
<
K
,
V
>
{
let
cap
=
num
::
max
(
INITIAL_CAPACITY
,
capacity
);
let
cap
=
max
(
INITIAL_CAPACITY
,
capacity
);
HashMap
{
k0
:
k0
,
k1
:
k1
,
resize_at
:
resize_at
(
cap
),
...
...
src/libstd/io/buffered.rs
浏览文件 @
68129d29
...
...
@@ -10,10 +10,10 @@
//! Buffering wrappers for I/O traits
use
cmp
;
use
container
::
Container
;
use
io
::{
Reader
,
Writer
,
Stream
,
Buffer
,
DEFAULT_BUF_SIZE
,
IoResult
};
use
iter
::
ExactSize
;
use
num
;
use
option
::{
Some
,
None
};
use
result
::{
Ok
,
Err
};
use
vec
::{
OwnedVector
,
ImmutableVector
,
MutableVector
};
...
...
@@ -104,7 +104,7 @@ impl<R: Reader> Reader for BufferedReader<R> {
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
IoResult
<
uint
>
{
let
nread
=
{
let
available
=
if_ok!
(
self
.fill
());
let
nread
=
num
::
min
(
available
.len
(),
buf
.len
());
let
nread
=
cmp
::
min
(
available
.len
(),
buf
.len
());
vec
::
bytes
::
copy_memory
(
buf
,
available
.slice_to
(
nread
));
nread
};
...
...
src/libstd/num/f32.rs
浏览文件 @
68129d29
...
...
@@ -189,42 +189,6 @@ fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
fn
gt
(
&
self
,
other
:
&
f32
)
->
bool
{
(
*
self
)
>
(
*
other
)
}
}
impl
Orderable
for
f32
{
/// Returns `NAN` if either of the numbers are `NAN`.
#[inline]
fn
min
(
&
self
,
other
:
&
f32
)
->
f32
{
match
()
{
_
if
self
.is_nan
()
=>
*
self
,
_
if
other
.is_nan
()
=>
*
other
,
_
if
*
self
<
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns `NAN` if either of the numbers are `NAN`.
#[inline]
fn
max
(
&
self
,
other
:
&
f32
)
->
f32
{
match
()
{
_
if
self
.is_nan
()
=>
*
self
,
_
if
other
.is_nan
()
=>
*
other
,
_
if
*
self
>
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns the number constrained within the range `mn <= self <= mx`.
/// If any of the numbers are `NAN` then `NAN` is returned.
#[inline]
fn
clamp
(
&
self
,
mn
:
&
f32
,
mx
:
&
f32
)
->
f32
{
match
()
{
_
if
self
.is_nan
()
=>
*
self
,
_
if
!
(
*
self
<=
*
mx
)
=>
*
mx
,
_
if
!
(
*
self
>=
*
mn
)
=>
*
mn
,
_
=>
*
self
,
}
}
}
impl
Default
for
f32
{
#[inline]
fn
default
()
->
f32
{
0.0
}
...
...
@@ -913,30 +877,6 @@ fn test_num() {
num
::
test_num
(
10f32
,
2f32
);
}
#[test]
fn
test_min
()
{
assert_eq!
(
1f32
.min
(
&
2f32
),
1f32
);
assert_eq!
(
2f32
.min
(
&
1f32
),
1f32
);
}
#[test]
fn
test_max
()
{
assert_eq!
(
1f32
.max
(
&
2f32
),
2f32
);
assert_eq!
(
2f32
.max
(
&
1f32
),
2f32
);
}
#[test]
fn
test_clamp
()
{
assert_eq!
(
1f32
.clamp
(
&
2f32
,
&
4f32
),
2f32
);
assert_eq!
(
8f32
.clamp
(
&
2f32
,
&
4f32
),
4f32
);
assert_eq!
(
3f32
.clamp
(
&
2f32
,
&
4f32
),
3f32
);
let
nan
:
f32
=
Float
::
nan
();
assert
!
(
3f32
.clamp
(
&
nan
,
&
4f32
)
.is_nan
());
assert
!
(
3f32
.clamp
(
&
2f32
,
&
nan
)
.is_nan
());
assert
!
(
nan
.clamp
(
&
2f32
,
&
4f32
)
.is_nan
());
}
#[test]
fn
test_floor
()
{
assert_approx_eq!
(
1.0f32
.floor
(),
1.0f32
);
...
...
src/libstd/num/f64.rs
浏览文件 @
68129d29
...
...
@@ -196,42 +196,6 @@ fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
fn
gt
(
&
self
,
other
:
&
f64
)
->
bool
{
(
*
self
)
>
(
*
other
)
}
}
impl
Orderable
for
f64
{
/// Returns `NAN` if either of the numbers are `NAN`.
#[inline]
fn
min
(
&
self
,
other
:
&
f64
)
->
f64
{
match
()
{
_
if
self
.is_nan
()
=>
*
self
,
_
if
other
.is_nan
()
=>
*
other
,
_
if
*
self
<
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns `NAN` if either of the numbers are `NAN`.
#[inline]
fn
max
(
&
self
,
other
:
&
f64
)
->
f64
{
match
()
{
_
if
self
.is_nan
()
=>
*
self
,
_
if
other
.is_nan
()
=>
*
other
,
_
if
*
self
>
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns the number constrained within the range `mn <= self <= mx`.
/// If any of the numbers are `NAN` then `NAN` is returned.
#[inline]
fn
clamp
(
&
self
,
mn
:
&
f64
,
mx
:
&
f64
)
->
f64
{
match
()
{
_
if
self
.is_nan
()
=>
*
self
,
_
if
!
(
*
self
<=
*
mx
)
=>
*
mx
,
_
if
!
(
*
self
>=
*
mn
)
=>
*
mn
,
_
=>
*
self
,
}
}
}
impl
Default
for
f64
{
#[inline]
fn
default
()
->
f64
{
0.0
}
...
...
@@ -915,38 +879,6 @@ fn test_num() {
num
::
test_num
(
10f64
,
2f64
);
}
#[test]
fn
test_min
()
{
assert_eq!
(
1f64
.min
(
&
2f64
),
1f64
);
assert_eq!
(
2f64
.min
(
&
1f64
),
1f64
);
let
nan
:
f64
=
Float
::
nan
();
assert
!
(
1f64
.min
(
&
nan
)
.is_nan
());
assert
!
(
nan
.min
(
&
1f64
)
.is_nan
());
}
#[test]
fn
test_max
()
{
assert_eq!
(
1f64
.max
(
&
2f64
),
2f64
);
assert_eq!
(
2f64
.max
(
&
1f64
),
2f64
);
let
nan
:
f64
=
Float
::
nan
();
assert
!
(
1f64
.max
(
&
nan
)
.is_nan
());
assert
!
(
nan
.max
(
&
1f64
)
.is_nan
());
}
#[test]
fn
test_clamp
()
{
assert_eq!
(
1f64
.clamp
(
&
2f64
,
&
4f64
),
2f64
);
assert_eq!
(
8f64
.clamp
(
&
2f64
,
&
4f64
),
4f64
);
assert_eq!
(
3f64
.clamp
(
&
2f64
,
&
4f64
),
3f64
);
let
nan
:
f64
=
Float
::
nan
();
assert
!
(
3f64
.clamp
(
&
nan
,
&
4f64
)
.is_nan
());
assert
!
(
3f64
.clamp
(
&
2f64
,
&
nan
)
.is_nan
());
assert
!
(
nan
.clamp
(
&
2f64
,
&
4f64
)
.is_nan
());
}
#[test]
fn
test_floor
()
{
assert_approx_eq!
(
1.0f64
.floor
(),
1.0f64
);
...
...
src/libstd/num/int_macros.rs
浏览文件 @
68129d29
...
...
@@ -53,24 +53,6 @@ impl Eq for $T {
fn
eq
(
&
self
,
other
:
&
$T
)
->
bool
{
return
(
*
self
)
==
(
*
other
);
}
}
impl
Orderable
for
$T
{
#[inline]
fn
min
(
&
self
,
other
:
&
$T
)
->
$T
{
if
*
self
<
*
other
{
*
self
}
else
{
*
other
}
}
#[inline]
fn
max
(
&
self
,
other
:
&
$T
)
->
$T
{
if
*
self
>
*
other
{
*
self
}
else
{
*
other
}
}
#[inline]
fn
clamp
(
&
self
,
mn
:
&
$T
,
mx
:
&
$T
)
->
$T
{
if
*
self
>
*
mx
{
*
mx
}
else
if
*
self
<
*
mn
{
*
mn
}
else
{
*
self
}
}
}
impl
Default
for
$T
{
#[inline]
fn
default
()
->
$T
{
0
}
...
...
@@ -457,17 +439,6 @@ fn test_num() {
num
::
test_num
(
10
as
$T
,
2
as
$T
);
}
#[test]
fn
test_orderable
()
{
assert_eq!
((
1
as
$T
)
.min
(
&
(
2
as
$T
)),
1
as
$T
);
assert_eq!
((
2
as
$T
)
.min
(
&
(
1
as
$T
)),
1
as
$T
);
assert_eq!
((
1
as
$T
)
.max
(
&
(
2
as
$T
)),
2
as
$T
);
assert_eq!
((
2
as
$T
)
.max
(
&
(
1
as
$T
)),
2
as
$T
);
assert_eq!
((
1
as
$T
)
.clamp
(
&
(
2
as
$T
),
&
(
4
as
$T
)),
2
as
$T
);
assert_eq!
((
8
as
$T
)
.clamp
(
&
(
2
as
$T
),
&
(
4
as
$T
)),
4
as
$T
);
assert_eq!
((
3
as
$T
)
.clamp
(
&
(
2
as
$T
),
&
(
4
as
$T
)),
3
as
$T
);
}
#[test]
pub
fn
test_abs
()
{
assert_eq!
((
1
as
$T
)
.abs
(),
1
as
$T
);
...
...
src/libstd/num/mod.rs
浏览文件 @
68129d29
...
...
@@ -33,23 +33,6 @@ pub trait Num: Eq + Zero + One
+
Div
<
Self
,
Self
>
+
Rem
<
Self
,
Self
>
{}
pub
trait
Orderable
:
Ord
{
// These should be methods on `Ord`, with overridable default implementations. We don't want
// to encumber all implementors of Ord by requiring them to implement these functions, but at
// the same time we want to be able to take advantage of the speed of the specific numeric
// functions (like the `fmin` and `fmax` intrinsics).
fn
min
(
&
self
,
other
:
&
Self
)
->
Self
;
fn
max
(
&
self
,
other
:
&
Self
)
->
Self
;
fn
clamp
(
&
self
,
mn
:
&
Self
,
mx
:
&
Self
)
->
Self
;
}
/// Return the smaller number.
#[inline(always)]
pub
fn
min
<
T
:
Orderable
>
(
x
:
T
,
y
:
T
)
->
T
{
x
.min
(
&
y
)
}
/// Return the larger number.
#[inline(always)]
pub
fn
max
<
T
:
Orderable
>
(
x
:
T
,
y
:
T
)
->
T
{
x
.max
(
&
y
)
}
/// Returns the number constrained within the range `mn <= self <= mx`.
#[inline(always)]
pub
fn
clamp
<
T
:
Orderable
>
(
value
:
T
,
mn
:
T
,
mx
:
T
)
->
T
{
value
.clamp
(
&
mn
,
&
mx
)
}
/// Defines an additive identity element for `Self`.
///
/// # Deriving
...
...
@@ -140,7 +123,7 @@ pub trait Signed: Num
pub
trait
Unsigned
:
Num
{}
pub
trait
Integer
:
Num
+
Ord
erable
+
Ord
+
Div
<
Self
,
Self
>
+
Rem
<
Self
,
Self
>
{
fn
div_rem
(
&
self
,
other
:
&
Self
)
->
(
Self
,
Self
);
...
...
@@ -185,7 +168,7 @@ pub trait Round {
/// Defines constants and methods common to real numbers
pub
trait
Real
:
Signed
+
Ord
erable
+
Ord
+
Round
+
Div
<
Self
,
Self
>
{
// Common Constants
...
...
@@ -434,7 +417,7 @@ pub trait Primitive: Clone
+
DeepClone
+
Num
+
NumCast
+
Ord
erable
+
Ord
+
Bounded
{}
/// A collection of traits relevant to primitive signed and unsigned integers
...
...
src/libstd/num/uint_macros.rs
浏览文件 @
68129d29
...
...
@@ -44,28 +44,6 @@ impl Eq for $T {
fn
eq
(
&
self
,
other
:
&
$T
)
->
bool
{
return
(
*
self
)
==
(
*
other
);
}
}
impl
Orderable
for
$T
{
#[inline]
fn
min
(
&
self
,
other
:
&
$T
)
->
$T
{
if
*
self
<
*
other
{
*
self
}
else
{
*
other
}
}
#[inline]
fn
max
(
&
self
,
other
:
&
$T
)
->
$T
{
if
*
self
>
*
other
{
*
self
}
else
{
*
other
}
}
/// Returns the number constrained within the range `mn <= self <= mx`.
#[inline]
fn
clamp
(
&
self
,
mn
:
&
$T
,
mx
:
&
$T
)
->
$T
{
match
()
{
_
if
(
*
self
>
*
mx
)
=>
*
mx
,
_
if
(
*
self
<
*
mn
)
=>
*
mn
,
_
=>
*
self
,
}
}
}
impl
Default
for
$T
{
#[inline]
fn
default
()
->
$T
{
0
}
...
...
@@ -329,17 +307,6 @@ fn test_num() {
num
::
test_num
(
10
as
$T
,
2
as
$T
);
}
#[test]
fn
test_orderable
()
{
assert_eq!
((
1
as
$T
)
.min
(
&
(
2
as
$T
)),
1
as
$T
);
assert_eq!
((
2
as
$T
)
.min
(
&
(
1
as
$T
)),
1
as
$T
);
assert_eq!
((
1
as
$T
)
.max
(
&
(
2
as
$T
)),
2
as
$T
);
assert_eq!
((
2
as
$T
)
.max
(
&
(
1
as
$T
)),
2
as
$T
);
assert_eq!
((
1
as
$T
)
.clamp
(
&
(
2
as
$T
),
&
(
4
as
$T
)),
2
as
$T
);
assert_eq!
((
8
as
$T
)
.clamp
(
&
(
2
as
$T
),
&
(
4
as
$T
)),
4
as
$T
);
assert_eq!
((
3
as
$T
)
.clamp
(
&
(
2
as
$T
),
&
(
4
as
$T
)),
3
as
$T
);
}
#[test]
fn
test_div_mod_floor
()
{
assert_eq!
((
10
as
$T
)
.div_floor
(
&
(
3
as
$T
)),
3
as
$T
);
...
...
src/libstd/prelude.rs
浏览文件 @
68129d29
...
...
@@ -59,7 +59,7 @@
pub
use
iter
::{
Iterator
,
DoubleEndedIterator
,
RandomAccessIterator
,
CloneableIterator
};
pub
use
iter
::{
OrdIterator
,
MutableDoubleEndedIterator
,
ExactSize
};
pub
use
num
::{
Integer
,
Real
,
Num
,
NumCast
,
CheckedAdd
,
CheckedSub
,
CheckedMul
};
pub
use
num
::{
Orderable
,
Signed
,
Unsigned
,
Round
};
pub
use
num
::{
Signed
,
Unsigned
,
Round
};
pub
use
num
::{
Primitive
,
Int
,
Float
,
ToStrRadix
,
ToPrimitive
,
FromPrimitive
};
pub
use
path
::{
GenericPath
,
Path
,
PosixPath
,
WindowsPath
};
pub
use
ptr
::
RawPtr
;
...
...
src/libsyntax/ast_util.rs
浏览文件 @
68129d29
...
...
@@ -18,10 +18,10 @@
use
visit
;
use
std
::
cell
::{
Cell
,
RefCell
};
use
std
::
cmp
;
use
std
::
hashmap
::
HashMap
;
use
std
::
u32
;
use
std
::
local_data
;
use
std
::
num
;
pub
fn
path_name_i
(
idents
:
&
[
Ident
])
->
~
str
{
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
...
...
@@ -343,8 +343,8 @@ pub fn empty(&self) -> bool {
}
pub
fn
add
(
&
mut
self
,
id
:
NodeId
)
{
self
.min
=
num
::
min
(
self
.min
,
id
);
self
.max
=
num
::
max
(
self
.max
,
id
+
1
);
self
.min
=
cmp
::
min
(
self
.min
,
id
);
self
.max
=
cmp
::
max
(
self
.max
,
id
+
1
);
}
}
...
...
src/test/bench/shootout-fasta.rs
浏览文件 @
68129d29
...
...
@@ -16,7 +16,7 @@
use
std
::
io
;
use
std
::
io
::{
BufferedWriter
,
File
};
use
std
::
num
::
min
;
use
std
::
cmp
::
min
;
use
std
::
os
;
static
LINE_LENGTH
:
uint
=
60
;
...
...
src/test/bench/shootout-spectralnorm.rs
浏览文件 @
68129d29
...
...
@@ -14,7 +14,7 @@
use
std
::
from_str
::
FromStr
;
use
std
::
iter
::
count
;
use
std
::
num
::
min
;
use
std
::
cmp
::
min
;
use
std
::
os
;
use
std
::
vec
::
from_elem
;
use
sync
::
Arc
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录