Skip to content

Commit c560551

Browse files
committed
---
yaml --- r: 92030 b: refs/heads/auto c: c470184 h: refs/heads/master v: v3
1 parent d30e28a commit c560551

File tree

7 files changed

+136
-15
lines changed

7 files changed

+136
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 8b964bf34901b01bdd461f7830ed46fc1ff4e223
16+
refs/heads/auto: c470184c20167f9f41613d5f4a1d75840e0f5c3a
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ CFG_PREFIX=${CFG_PREFIX%/}
607607
CFG_MANDIR=${CFG_MANDIR%/}
608608
CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
609609
CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"
610-
CFG_SUPPORTED_TARGET="$(grep ^CC_*=* $CFG_SRC_DIR/mk/platform.mk | sed -e 's/^CC_//' -e 's/\([^=]*\).*/\1/' | xargs)"
610+
CFG_SUPPORTED_TARGET="$(grep ^CC_*=* ${CFG_SRC_DIR}mk/platform.mk | sed -e 's/^CC_//' -e 's/\([^=]*\).*/\1/' | xargs)"
611611

612612
# copy host-triples to target-triples so that hosts are a subset of targets
613613
V_TEMP=""

branches/auto/mk/llvm.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ LLVM_DEPS := $(S)/.gitmodules
1414
else
1515

1616
# This is just a rough approximation of LLVM deps
17-
LLVM_DEPS_SRC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)/lib,*cpp *hpp)
18-
LLVM_DEPS_INC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)/include,*cpp *hpp)
17+
LLVM_DEPS_SRC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)lib,*cpp *hpp)
18+
LLVM_DEPS_INC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)include,*cpp *hpp)
1919
LLVM_DEPS=$(LLVM_DEPS_SRC) $(LLVM_DEPS_INC)
2020
endif
2121

branches/auto/mk/tests.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ifdef CFG_UNIXY_$(1)
9898
endif
9999

100100
ifdef CFG_WINDOWSY_$(1)
101-
CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)/$$(2)/$$(strip \
101+
CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
102102
$$(if $$(findstring stage0,$$(1)), \
103103
stage0/$$(CFG_LIBDIR), \
104104
$$(if $$(findstring stage1,$$(1)), \

branches/auto/src/libstd/io/buffered.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,19 @@ impl<W: Writer> BufferedWriter<W> {
166166
pub fn new(inner: W) -> BufferedWriter<W> {
167167
BufferedWriter::with_capacity(DEFAULT_CAPACITY, inner)
168168
}
169+
170+
fn flush_buf(&mut self) {
171+
if self.pos != 0 {
172+
self.inner.write(self.buf.slice_to(self.pos));
173+
self.pos = 0;
174+
}
175+
}
169176
}
170177

171178
impl<W: Writer> Writer for BufferedWriter<W> {
172179
fn write(&mut self, buf: &[u8]) {
173180
if self.pos + buf.len() > self.buf.len() {
174-
self.flush();
181+
self.flush_buf();
175182
}
176183

177184
if buf.len() > self.buf.len() {
@@ -184,16 +191,13 @@ impl<W: Writer> Writer for BufferedWriter<W> {
184191
}
185192

186193
fn flush(&mut self) {
187-
if self.pos != 0 {
188-
self.inner.write(self.buf.slice_to(self.pos));
189-
self.pos = 0;
190-
}
194+
self.flush_buf();
191195
self.inner.flush();
192196
}
193197
}
194198

195199
impl<W: Writer> Decorator<W> for BufferedWriter<W> {
196-
fn inner(self) -> W { self.inner }
200+
fn inner(mut self) -> W { self.flush_buf(); self.inner }
197201
fn inner_ref<'a>(&'a self) -> &'a W { &self.inner }
198202
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut W { &mut self.inner }
199203
}
@@ -218,7 +222,7 @@ impl<W: Writer> LineBufferedWriter<W> {
218222

219223
impl<W: Writer> Writer for LineBufferedWriter<W> {
220224
fn write(&mut self, buf: &[u8]) {
221-
match buf.iter().position(|&b| b == '\n' as u8) {
225+
match buf.iter().rposition(|&b| b == '\n' as u8) {
222226
Some(i) => {
223227
self.inner.write(buf.slice_to(i + 1));
224228
self.inner.flush();
@@ -387,6 +391,15 @@ mod test {
387391
writer.inner_ref().inner_ref().as_slice());
388392
}
389393

394+
#[test]
395+
fn test_buffered_writer_inner_flushes() {
396+
let mut w = BufferedWriter::with_capacity(3, MemWriter::new());
397+
w.write([0, 1]);
398+
assert_eq!([], w.inner_ref().inner_ref().as_slice());
399+
let w = w.inner();
400+
assert_eq!([0, 1], w.inner_ref().as_slice());
401+
}
402+
390403
// This is just here to make sure that we don't infinite loop in the
391404
// newtype struct autoderef weirdness
392405
#[test]
@@ -430,10 +443,15 @@ mod test {
430443
assert_eq!(*writer.inner_ref().inner_ref(), ~[]);
431444
writer.flush();
432445
assert_eq!(*writer.inner_ref().inner_ref(), ~[0, 1]);
433-
writer.write([0, '\n' as u8, 1]);
434-
assert_eq!(*writer.inner_ref().inner_ref(), ~[0, 1, 0, '\n' as u8]);
446+
writer.write([0, '\n' as u8, 1, '\n' as u8, 2]);
447+
assert_eq!(*writer.inner_ref().inner_ref(),
448+
~[0, 1, 0, '\n' as u8, 1, '\n' as u8]);
435449
writer.flush();
436-
assert_eq!(*writer.inner_ref().inner_ref(), ~[0, 1, 0, '\n' as u8, 1]);
450+
assert_eq!(*writer.inner_ref().inner_ref(),
451+
~[0, 1, 0, '\n' as u8, 1, '\n' as u8, 2]);
452+
writer.write([3, '\n' as u8]);
453+
assert_eq!(*writer.inner_ref().inner_ref(),
454+
~[0, 1, 0, '\n' as u8, 1, '\n' as u8, 2, 3, '\n' as u8]);
437455
}
438456

439457
#[bench]

branches/auto/src/libstd/rt/deque.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ mod tests {
590590
}
591591

592592
#[test]
593+
#[ignore(cfg(windows))] // apparently windows scheduling is weird?
593594
fn no_starvation() {
594595
static AMT: int = 10000;
595596
static NTHREADS: int = 4;

branches/auto/src/libstd/vec.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,18 @@ pub trait MutableVector<'self, T> {
19331933
/// Returns a reversed iterator that allows modifying each value
19341934
fn mut_rev_iter(self) -> MutRevIterator<'self, T>;
19351935

1936+
/**
1937+
* Returns an iterator over `size` elements of the vector at a time.
1938+
* The chunks are mutable and do not overlap. If `size` does not divide the
1939+
* length of the vector, then the last chunk will not have length
1940+
* `size`.
1941+
*
1942+
* # Failure
1943+
*
1944+
* Fails if `size` is 0.
1945+
*/
1946+
fn mut_chunks(self, chunk_size: uint) -> MutChunkIter<'self, T>;
1947+
19361948
/**
19371949
* Returns a mutable reference to the first element in this slice
19381950
* and adjusts the slice in place so that it no longer contains
@@ -2069,6 +2081,13 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
20692081
self.mut_iter().invert()
20702082
}
20712083

2084+
#[inline]
2085+
fn mut_chunks(self, chunk_size: uint) -> MutChunkIter<'self, T> {
2086+
assert!(chunk_size > 0);
2087+
let len = self.len();
2088+
MutChunkIter { v: self, chunk_size: chunk_size, remaining: len }
2089+
}
2090+
20722091
fn mut_shift_ref(&mut self) -> &'self mut T {
20732092
unsafe {
20742093
let s: &mut Slice<T> = cast::transmute(self);
@@ -2556,6 +2575,59 @@ impl<'self, T> Clone for VecIterator<'self, T> {
25562575
iterator!{struct VecMutIterator -> *mut T, &'self mut T}
25572576
pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>;
25582577

2578+
/// An iterator over a vector in (non-overlapping) mutable chunks (`size` elements at a time). When
2579+
/// the vector len is not evenly divided by the chunk size, the last slice of the iteration will be
2580+
/// the remainder.
2581+
pub struct MutChunkIter<'self, T> {
2582+
priv v: &'self mut [T],
2583+
priv chunk_size: uint,
2584+
priv remaining: uint
2585+
}
2586+
2587+
impl<'self, T> Iterator<&'self mut [T]> for MutChunkIter<'self, T> {
2588+
#[inline]
2589+
fn next(&mut self) -> Option<&'self mut [T]> {
2590+
if self.remaining == 0 {
2591+
None
2592+
} else {
2593+
let sz = cmp::min(self.remaining, self.chunk_size);
2594+
let tmp = util::replace(&mut self.v, &mut []);
2595+
let (head, tail) = tmp.mut_split(sz);
2596+
self.v = tail;
2597+
self.remaining -= sz;
2598+
Some(head)
2599+
}
2600+
}
2601+
2602+
#[inline]
2603+
fn size_hint(&self) -> (uint, Option<uint>) {
2604+
if self.remaining == 0 {
2605+
(0, Some(0))
2606+
} else {
2607+
let (n, rem) = self.remaining.div_rem(&self.chunk_size);
2608+
let n = if rem > 0 { n + 1 } else { n };
2609+
(n, Some(n))
2610+
}
2611+
}
2612+
}
2613+
2614+
impl<'self, T> DoubleEndedIterator<&'self mut [T]> for MutChunkIter<'self, T> {
2615+
#[inline]
2616+
fn next_back(&mut self) -> Option<&'self mut [T]> {
2617+
if self.remaining == 0 {
2618+
None
2619+
} else {
2620+
let remainder = self.remaining % self.chunk_size;
2621+
let sz = if remainder != 0 { remainder } else { self.chunk_size };
2622+
let tmp = util::replace(&mut self.v, &mut []);
2623+
let (head, tail) = tmp.mut_split(self.remaining - sz);
2624+
self.v = head;
2625+
self.remaining -= sz;
2626+
Some(tail)
2627+
}
2628+
}
2629+
}
2630+
25592631
/// An iterator that moves out of a vector.
25602632
#[deriving(Clone)]
25612633
pub struct MoveIterator<T> {
@@ -3966,6 +4038,36 @@ mod tests {
39664038
x.pop_ref();
39674039
}
39684040

4041+
#[test]
4042+
fn test_mut_chunks() {
4043+
let mut v = [0u8, 1, 2, 3, 4, 5, 6];
4044+
for (i, chunk) in v.mut_chunks(3).enumerate() {
4045+
for x in chunk.mut_iter() {
4046+
*x = i as u8;
4047+
}
4048+
}
4049+
let result = [0u8, 0, 0, 1, 1, 1, 2];
4050+
assert_eq!(v, result);
4051+
}
4052+
4053+
#[test]
4054+
fn test_mut_chunks_invert() {
4055+
let mut v = [0u8, 1, 2, 3, 4, 5, 6];
4056+
for (i, chunk) in v.mut_chunks(3).invert().enumerate() {
4057+
for x in chunk.mut_iter() {
4058+
*x = i as u8;
4059+
}
4060+
}
4061+
let result = [2u8, 2, 2, 1, 1, 1, 0];
4062+
assert_eq!(v, result);
4063+
}
4064+
4065+
#[test]
4066+
#[should_fail]
4067+
fn test_mut_chunks_0() {
4068+
let mut v = [1, 2, 3, 4];
4069+
let _it = v.mut_chunks(0);
4070+
}
39694071

39704072
#[test]
39714073
fn test_mut_shift_ref() {

0 commit comments

Comments
 (0)