Skip to content

aggregated small pull requests #8257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
26 changes: 12 additions & 14 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ impl<T:Freeze+Send> Arc<T> {
}
}

/**
* Duplicate an atomically reference counted wrapper.
*
* The resulting two `arc` objects will point to the same underlying data
* object. However, one of the `arc` objects can be sent to another task,
* allowing them to share the underlying data.
*/
impl<T:Freeze + Send> Clone for Arc<T> {
/**
* Duplicate an atomically reference counted wrapper.
*
* The resulting two `arc` objects will point to the same underlying data
* object. However, one of the `arc` objects can be sent to another task,
* allowing them to share the underlying data.
*/
fn clone(&self) -> Arc<T> {
Arc { x: self.x.clone() }
}
Expand All @@ -164,7 +164,7 @@ struct MutexArc<T> { priv x: UnsafeAtomicRcBox<MutexArcInner<T>> }


impl<T:Send> Clone for MutexArc<T> {
/// Duplicate a mutex-protected Arc, as arc::clone.
/// Duplicate a mutex-protected Arc. See arc::clone for more details.
fn clone(&self) -> MutexArc<T> {
// NB: Cloning the underlying mutex is not necessary. Its reference
// count would be exactly the same as the shared state's.
Expand Down Expand Up @@ -312,12 +312,10 @@ struct RWArc<T> {
priv x: UnsafeAtomicRcBox<RWArcInner<T>>,
}

impl<T:Freeze + Send> RWArc<T> {
/// Duplicate a rwlock-protected Arc, as arc::clone.
pub fn clone(&self) -> RWArc<T> {
RWArc {
x: self.x.clone(),
}
impl<T:Freeze + Send> Clone for RWArc<T> {
/// Duplicate a rwlock-protected Arc. See arc::clone for more details.
fn clone(&self) -> RWArc<T> {
RWArc { x: self.x.clone() }
}

}
Expand Down
12 changes: 6 additions & 6 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,9 +1638,9 @@ mod tests {
fn bench_btv_small_iter(b: &mut BenchHarness) {
let bitv = Bitv::new(uint::bits, false);
do b.iter {
let mut sum = 0;
let mut _sum = 0;
foreach pres in bitv.iter() {
sum += pres as uint;
_sum += pres as uint;
}
}
}
Expand All @@ -1649,9 +1649,9 @@ mod tests {
fn bench_bitv_big_iter(b: &mut BenchHarness) {
let bitv = Bitv::new(BENCH_BITS, false);
do b.iter {
let mut sum = 0;
let mut _sum = 0;
foreach pres in bitv.iter() {
sum += pres as uint;
_sum += pres as uint;
}
}
}
Expand All @@ -1661,9 +1661,9 @@ mod tests {
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
|idx| {idx % 3 == 0}));
do b.iter {
let mut sum = 0;
let mut _sum = 0;
foreach idx in bitv.iter() {
sum += idx;
_sum += idx;
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/libextra/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,12 @@ pub mod bytepipes {
#[cfg(test)]
mod test {

use flatpipes::{Flattener, Unflattener};
use flatpipes::bytepipes::*;
use flatpipes::BytePort;
use flatpipes::pod;
use flatpipes::serial;
use io_util::BufReader;
use flatpipes::{BytePort, FlatChan, FlatPort};

use std::comm;
use std::io::BytesWriter;
use std::result;
use std::task;

#[test]
Expand Down Expand Up @@ -727,7 +723,11 @@ mod test {

// FIXME #2064: Networking doesn't work on x86
// XXX Broken until networking support is added back
/*#[test]
/*
use flatpipes::{Flattener, Unflattener, FlatChan, FlatPort};
use flatpipes::bytepipes::*;

#[test]
#[cfg(target_arch = "x86_64")]
fn test_pod_tcp_stream() {
fn reader_port(buf: TcpSocketBuf
Expand Down Expand Up @@ -767,6 +767,8 @@ mod test {
port: uint) {

use std::cell::Cell;
use std::comm;
use std::result;
use net::ip;
use net::tcp;
use uv;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ fn store_non_ref_bindings(bcx: @mut Block,
add_clean_temp_mem(bcx, lldest, binding_info.ty);
temp_cleanups.push(lldest);
temp_cleanups
}
};
}
TrByRef => {}
}
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2750,13 +2750,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
}
ast::expr_vec(ref args, mutbl) => {
let t: ty::t = fcx.infcx().next_ty_var();
let mut arg_is_bot = false;
let mut arg_is_err = false;
foreach e in args.iter() {
check_expr_has_type(fcx, *e, t);
let arg_t = fcx.expr_ty(*e);
arg_is_bot |= ty::type_is_bot(arg_t);
arg_is_err |= ty::type_is_error(arg_t);
}
let typ = ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutbl},
ty::vstore_fixed(args.len()));
Expand Down
10 changes: 10 additions & 0 deletions src/libstd/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ pub fn log_type<T>(level: u32, object: &T) {
fn newsched_log_str(msg: ~str) {
use rt::task::Task;
use rt::local::Local;
use str::StrSlice;
use container::Container;

// Truncate the string
let buf_bytes = 256;
let msg = if msg.len() > buf_bytes {
msg.slice(0, buf_bytes) + "[...]"
} else {
msg
};

unsafe {
match Local::try_unsafe_borrow::<Task>() {
Expand Down
29 changes: 24 additions & 5 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,24 @@ impl<T> Option<T> {
self.take().map_consume_default(def, blk)
}

/// Apply a function to the contained value or do nothing
pub fn mutate(&mut self, f: &fn(T) -> T) {
/// Apply a function to the contained value or do nothing.
/// Returns true if the contained value was mutated.
pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
}
true
} else { false }
}

/// Apply a function to the contained value or set it to a default
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
/// Apply a function to the contained value or set it to a default.
/// Returns true if the contained value was mutated, or false if set to the default.
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
true
} else {
*self = Some(def);
false
}
}

Expand Down Expand Up @@ -575,4 +580,18 @@ mod tests {
assert_eq!(it.size_hint(), (0, Some(0)));
assert!(it.next().is_none());
}

#[test]
fn test_mutate() {
let mut x = Some(3i);
assert!(x.mutate(|i| i+1));
assert_eq!(x, Some(4i));
assert!(x.mutate_default(0, |i| i+1));
assert_eq!(x, Some(5i));
x = None;
assert!(!x.mutate(|i| i+1));
assert_eq!(x, None);
assert!(!x.mutate_default(0i, |i| i+1));
assert_eq!(x, Some(0i));
}
}
59 changes: 51 additions & 8 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,11 +2141,15 @@ macro_rules! iterator {
None
} else {
let old = self.ptr;
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
self.ptr = cast::transmute(self.ptr as uint +
sys::nonzero_size_of::<T>());
self.ptr = if sys::size_of::<T>() == 0 {
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
cast::transmute(self.ptr as uint + 1)
} else {
self.ptr.offset(1)
};

Some(cast::transmute(old))
}
}
Expand All @@ -2171,9 +2175,12 @@ macro_rules! double_ended_iterator {
if self.end == self.ptr {
None
} else {
// See above for why 'ptr.offset' isn't used
self.end = cast::transmute(self.end as uint -
sys::nonzero_size_of::<T>());
self.end = if sys::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
cast::transmute(self.end as uint - 1)
} else {
self.end.offset(-1)
};
Some(cast::transmute(self.end))
}
}
Expand Down Expand Up @@ -3566,3 +3573,39 @@ mod tests {
assert!(cnt == 3);
}
}

#[cfg(test)]
mod bench {
use extra::test::BenchHarness;
use vec;
use option::*;

#[bench]
fn iterator(bh: &mut BenchHarness) {
// peculiar numbers to stop LLVM from optimising the summation
// out.
let v = vec::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1));

do bh.iter {
let mut sum = 0;
foreach x in v.iter() {
sum += *x;
}
// sum == 11806, to stop dead code elimination.
if sum == 0 {fail!()}
}
}

#[bench]
fn mut_iterator(bh: &mut BenchHarness) {
let mut v = vec::from_elem(100, 0);

do bh.iter {
let mut i = 0;
foreach x in v.mut_iter() {
*x = i;
i += 1;
}
}
}
}
2 changes: 1 addition & 1 deletion src/test/run-fail/assert-macro-explicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'assertion failed: false'
// error-pattern:failed at 'assertion failed: false'

fn main() {
assert!(false);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/assert-macro-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'test-assert-fmt 42 rust'
// error-pattern:failed at 'test-assert-fmt 42 rust'

fn main() {
assert!(false, "test-assert-fmt %d %s", 42, "rust");
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/assert-macro-owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'test-assert-owned'
// error-pattern:failed at 'test-assert-owned'

fn main() {
assert!(false, ~"test-assert-owned");
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/assert-macro-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'test-assert-static'
// error-pattern:failed at 'test-assert-static'

fn main() {
assert!(false, "test-assert-static");
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/fail-macro-explicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'explicit failure'
// error-pattern:failed at 'explicit failure'

fn main() {
fail!();
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/fail-macro-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'test-fail-fmt 42 rust'
// error-pattern:failed at 'test-fail-fmt 42 rust'

fn main() {
fail!("test-fail-fmt %d %s", 42, "rust");
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/fail-macro-owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'test-fail-owned'
// error-pattern:failed at 'test-fail-owned'

fn main() {
fail!("test-fail-owned");
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/fail-macro-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:task failed at 'test-fail-static'
// error-pattern:failed at 'test-fail-static'

fn main() {
fail!("test-fail-static");
Expand Down