Skip to content

Commit d61889c

Browse files
committed
---
yaml --- r: 42731 b: refs/heads/try c: a72aeef h: refs/heads/master i: 42729: a3741d4 42727: 89ef194 v: v3
1 parent 5d237fc commit d61889c

File tree

5 files changed

+34
-53
lines changed

5 files changed

+34
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: fce6446e7e2683b5cfcc2a36211cec5ab2c355fa
5+
refs/heads/try: a72aeef9f7f1baa059e26c9eb35204aa65bafb7d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libcore/io.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ impl<T: Reader> T : ReaderUtil {
185185
}
186186

187187
fn read_line(&self) -> ~str {
188-
let mut line = ~"";
188+
let mut bytes = ~[];
189189
loop {
190190
let ch = self.read_byte();
191191
if ch == -1 || ch == 10 { break; }
192-
str::push_char(&mut line, ch as char);
192+
bytes.push(ch as u8);
193193
}
194-
line
194+
str::from_bytes(bytes)
195195
}
196196

197197
fn read_chars(&self, n: uint) -> ~[char] {
@@ -1221,6 +1221,14 @@ mod tests {
12211221
}
12221222
}
12231223

1224+
#[test]
1225+
fn test_read_line_utf8() {
1226+
do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| {
1227+
let line = inp.read_line();
1228+
assert line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
1229+
}
1230+
}
1231+
12241232
#[test]
12251233
fn test_readchars_wide() {
12261234
let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";

branches/try/src/libstd/cmp.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
#[forbid(deprecated_mode)];
12-
//! Additional general-purpose comparison functionality.
12+
/// Additional general-purpose comparison functionality.
1313
1414
use core::f32;
1515
use core::f64;
@@ -18,49 +18,31 @@ use core::float;
1818
const fuzzy_epsilon: float = 1.0e-6;
1919

2020
pub trait FuzzyEq {
21-
pure fn fuzzy_eq(&self, other: &self) -> bool;
22-
pure fn fuzzy_eq_eps(&self, other: &self, epsilon: &self) -> bool;
21+
pure fn fuzzy_eq(other: &self) -> bool;
2322
}
2423

2524
impl float: FuzzyEq {
26-
pure fn fuzzy_eq(&self, other: &float) -> bool {
27-
float::abs(*self - *other) < fuzzy_epsilon
28-
}
29-
30-
pure fn fuzzy_eq_eps(&self, other: &float, epsilon: &float) -> bool {
31-
float::abs(*self - *other) < *epsilon
25+
pure fn fuzzy_eq(other: &float) -> bool {
26+
return float::abs(self - *other) < fuzzy_epsilon;
3227
}
3328
}
3429

3530
impl f32: FuzzyEq {
36-
pure fn fuzzy_eq(&self, other: &f32) -> bool {
37-
f32::abs(*self - *other) < (fuzzy_epsilon as f32)
38-
}
39-
40-
pure fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
41-
f32::abs(*self - *other) < *epsilon
31+
pure fn fuzzy_eq(other: &f32) -> bool {
32+
return f32::abs(self - *other) < (fuzzy_epsilon as f32);
4233
}
4334
}
4435

4536
impl f64: FuzzyEq {
46-
pure fn fuzzy_eq(&self, other: &f64) -> bool {
47-
f64::abs(*self - *other) < (fuzzy_epsilon as f64)
48-
}
49-
50-
pure fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
51-
f64::abs(*self - *other) < *epsilon
37+
pure fn fuzzy_eq(other: &f64) -> bool {
38+
return f64::abs(self - *other) < (fuzzy_epsilon as f64);
5239
}
5340
}
5441

5542
#[test]
5643
fn test_fuzzy_equals() {
57-
assert (&1.0).fuzzy_eq(&1.0);
58-
assert (&1.0f32).fuzzy_eq(&1.0f32);
59-
assert (&1.0f64).fuzzy_eq(&1.0f64);
44+
assert ((&1.0).fuzzy_eq(&1.0));
45+
assert ((&1.0f32).fuzzy_eq(&1.0f32));
46+
assert ((&1.0f64).fuzzy_eq(&1.0f64));
6047
}
6148

62-
#[test]
63-
fn test_fuzzy_eq_eps() {
64-
assert (&1.2).fuzzy_eq_eps(&0.9, &0.5);
65-
assert !(&1.5).fuzzy_eq_eps(&0.9, &0.5);
66-
}

branches/try/src/libstd/priority_queue.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ impl <T: Ord> PriorityQueue<T> {
7676
}
7777

7878
/// Optimized version of a push followed by a pop
79-
fn push_pop(&mut self, item: T) -> T {
80-
let mut item = item;
79+
fn push_pop(&mut self, mut item: T) -> T {
8180
if !self.is_empty() && self.data[0] > item {
8281
item <-> self.data[0];
8382
self.siftdown(0);
@@ -86,8 +85,7 @@ impl <T: Ord> PriorityQueue<T> {
8685
}
8786

8887
/// Optimized version of a pop followed by a push - fails if empty
89-
fn replace(&mut self, item: T) -> T {
90-
let mut item = item;
88+
fn replace(&mut self, mut item: T) -> T {
9189
item <-> self.data[0];
9290
self.siftdown(0);
9391
item
@@ -129,9 +127,8 @@ impl <T: Ord> PriorityQueue<T> {
129127
// vector over the junk element. This reduces the constant factor
130128
// compared to using swaps, which involves twice as many moves.
131129

132-
priv fn siftup(&mut self, start: uint, pos: uint) {
130+
priv fn siftup(&mut self, start: uint, mut pos: uint) {
133131
unsafe {
134-
let mut pos = pos;
135132
let new = move *addr_of(&self.data[pos]);
136133

137134
while pos > start {
@@ -149,9 +146,8 @@ impl <T: Ord> PriorityQueue<T> {
149146
}
150147
}
151148

152-
priv fn siftdown_range(&mut self, pos: uint, end: uint) {
149+
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
153150
unsafe {
154-
let mut pos = pos;
155151
let start = pos;
156152
let new = move *addr_of(&self.data[pos]);
157153

branches/try/src/libstd/treemap.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,8 @@ pure fn each_reverse<K: Ord, V>(node: &Option<~TreeNode<K, V>>,
572572
}
573573

574574
// Remove left horizontal link by rotating right
575-
fn skew<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
575+
fn skew<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
576576
if node.left.map_default(false, |x| x.level == node.level) {
577-
let mut node = node;
578577
let mut save = node.left.swap_unwrap();
579578
node.left <-> save.right; // save.right now None
580579
save.right = Some(node);
@@ -586,10 +585,9 @@ fn skew<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
586585

587586
// Remove dual horizontal link by rotating left and increasing level of
588587
// the parent
589-
fn split<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
588+
fn split<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
590589
if node.right.map_default(false,
591590
|x| x.right.map_default(false, |y| y.level == node.level)) {
592-
let mut node = node;
593591
let mut save = node.right.swap_unwrap();
594592
node.right <-> save.left; // save.left now None
595593
save.left = Some(node);
@@ -628,8 +626,7 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
628626
fn heir_swap<K: Ord, V>(node: &mut TreeNode<K, V>,
629627
child: &mut Option<~TreeNode<K, V>>) {
630628
// *could* be done without recursion, but it won't borrow check
631-
do child.mutate |child| {
632-
let mut child = child;
629+
do child.mutate |mut child| {
633630
if child.right.is_some() {
634631
heir_swap(&mut *node, &mut child.right);
635632
} else {
@@ -682,15 +679,13 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
682679
save.level -= 1;
683680

684681
if right_level > save.level {
685-
do save.right.mutate |x| {
686-
let mut x = x; x.level = save.level; x
687-
}
682+
do save.right.mutate |mut x| { x.level = save.level; x }
688683
}
689684

690685
save = skew(save);
691686

692-
do save.right.mutate |right| {
693-
let mut right = skew(right);
687+
do save.right.mutate |mut right| {
688+
right = skew(right);
694689
right.right.mutate(skew);
695690
right
696691
}

0 commit comments

Comments
 (0)