Skip to content

Commit b416d97

Browse files
committed
---
yaml --- r: 140778 b: refs/heads/try2 c: 5a2f65f h: refs/heads/master v: v3
1 parent 28ea8f8 commit b416d97

File tree

5 files changed

+75
-60
lines changed

5 files changed

+75
-60
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 66e1e517019c70450dcadeb0d876c686729215e3
8+
refs/heads/try2: 5a2f65fb5035627b8fb0b1ce0e927a492d55e3a4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/vec.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,8 +1683,8 @@ pub fn eachi_reverse<'r,T>(v: &'r [T],
16831683
*/
16841684
#[inline]
16851685
pub fn _each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
1686-
assert!(len(v1) == len(v2));
1687-
for uint::range(0u, len(v1)) |i| {
1686+
assert!(v1.len() == v2.len());
1687+
for uint::range(0u, v1.len()) |i| {
16881688
if !f(&v1[i], &v2[i]) {
16891689
return false;
16901690
}
@@ -1701,6 +1701,35 @@ pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
17011701
_each2(v1, v2, f)
17021702
}
17031703
1704+
/**
1705+
*
1706+
* Iterates over two vector with mutable.
1707+
*
1708+
* # Failure
1709+
*
1710+
* Both vectors must have the same length
1711+
*/
1712+
#[inline]
1713+
pub fn _each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
1714+
assert!(v1.len() == v2.len());
1715+
for uint::range(0u, v1.len()) |i| {
1716+
if !f(&mut v1[i], &mut v2[i]) {
1717+
return false;
1718+
}
1719+
}
1720+
return true;
1721+
}
1722+
1723+
#[cfg(stage0)]
1724+
pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) {
1725+
_each2_mut(v1, v2, f);
1726+
}
1727+
1728+
#[cfg(not(stage0))]
1729+
pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
1730+
_each2_mut(v1, v2, f)
1731+
}
1732+
17041733
/**
17051734
* Iterate over all permutations of vector `v`.
17061735
*

branches/try2/src/libstd/priority_queue.rs

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
1313
use core::old_iter::BaseIter;
1414
use core::util::{replace, swap};
15-
16-
#[abi = "rust-intrinsic"]
17-
extern "rust-intrinsic" {
18-
fn move_val_init<T>(dst: &mut T, src: T);
19-
fn init<T>() -> T;
20-
#[cfg(not(stage0))]
21-
fn uninit<T>() -> T;
22-
}
15+
use core::unstable::intrinsics::{init, move_val_init};
2316

2417
pub struct PriorityQueue<T> {
2518
priv data: ~[T],
@@ -141,33 +134,13 @@ pub impl <T:Ord> PriorityQueue<T> {
141134

142135
// The implementations of siftup and siftdown use unsafe blocks in
143136
// order to move an element out of the vector (leaving behind a
144-
// junk element), shift along the others and move it back into the
137+
// zeroed element), shift along the others and move it back into the
145138
// vector over the junk element. This reduces the constant factor
146139
// compared to using swaps, which involves twice as many moves.
147140

148-
#[cfg(not(stage0))]
149-
priv fn siftup(&mut self, start: uint, mut pos: uint) {
150-
unsafe {
151-
let new = *ptr::to_unsafe_ptr(&self.data[pos]);
152-
153-
while pos > start {
154-
let parent = (pos - 1) >> 1;
155-
if new > self.data[parent] {
156-
let x = replace(&mut self.data[parent], uninit());
157-
move_val_init(&mut self.data[pos], x);
158-
pos = parent;
159-
loop
160-
}
161-
break
162-
}
163-
move_val_init(&mut self.data[pos], new);
164-
}
165-
}
166-
167-
#[cfg(stage0)]
168141
priv fn siftup(&mut self, start: uint, mut pos: uint) {
169142
unsafe {
170-
let new = *ptr::to_unsafe_ptr(&self.data[pos]);
143+
let new = replace(&mut self.data[pos], init());
171144

172145
while pos > start {
173146
let parent = (pos - 1) >> 1;
@@ -183,35 +156,10 @@ pub impl <T:Ord> PriorityQueue<T> {
183156
}
184157
}
185158

186-
187-
#[cfg(not(stage0))]
188-
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
189-
unsafe {
190-
let start = pos;
191-
let new = *ptr::to_unsafe_ptr(&self.data[pos]);
192-
193-
let mut child = 2 * pos + 1;
194-
while child < end {
195-
let right = child + 1;
196-
if right < end && !(self.data[child] > self.data[right]) {
197-
child = right;
198-
}
199-
let x = replace(&mut self.data[child], uninit());
200-
move_val_init(&mut self.data[pos], x);
201-
pos = child;
202-
child = 2 * pos + 1;
203-
}
204-
205-
move_val_init(&mut self.data[pos], new);
206-
self.siftup(start, pos);
207-
}
208-
}
209-
210-
#[cfg(stage0)]
211159
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
212160
unsafe {
213161
let start = pos;
214-
let new = *ptr::to_unsafe_ptr(&self.data[pos]);
162+
let new = replace(&mut self.data[pos], init());
215163

216164
let mut child = 2 * pos + 1;
217165
while child < end {

branches/try2/src/libuv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 218ab86721eefd7b7e97fa6d9f95a80a1fa8686c
1+
Subproject commit 97ac7c087a0caf6b0f611b80e14f7fe3cb18bb27
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// -*- rust -*-
12+
fn main(){
13+
let mut t1 = ~[];
14+
t1.push('a');
15+
16+
let mut t2 = ~[];
17+
t2.push('b');
18+
19+
for vec::each2_mut(t1, t2) | i1, i2 | {
20+
assert!(*i1 == 'a');
21+
assert!(*i2 == 'b');
22+
}
23+
24+
for vec::each2(t1, t2) | i1, i2 | {
25+
io::println(fmt!("after t1: %?, t2: %?", i1, i2));
26+
}
27+
28+
for vec::each2_mut(t1, t2) | i1, i2 | {
29+
*i1 = 'b';
30+
*i2 = 'a';
31+
assert!(*i1 == 'b');
32+
assert!(*i2 == 'a');
33+
}
34+
35+
for vec::each2(t1, t2) | i1, i2 | {
36+
io::println(fmt!("before t1: %?, t2: %?", i1, i2));
37+
}
38+
}

0 commit comments

Comments
 (0)