Skip to content

Commit

Permalink
Merge pull request #4625 from thestinger/container
Browse files Browse the repository at this point in the history
more little container improvements
  • Loading branch information
catamorphism committed Jan 25, 2013
2 parents 4a7e1ab + e4337a9 commit 85a34c2
Show file tree
Hide file tree
Showing 33 changed files with 66 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn parse_config(args: ~[~str]) -> config {
getopts::optopt(~"logfile"),
getopts::optflag(~"jit")];

assert (vec::is_not_empty(args));
assert !args.is_empty();
let args_ = vec::tail(args);
let matches =
&match getopts::getopts(args_, opts) {
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ fn run_cfail_test(config: config, props: test_props, testfile: &Path) {
check_correct_failure_status(procres);

let expected_errors = errors::load_errors(testfile);
if vec::is_not_empty(expected_errors) {
if vec::is_not_empty(props.error_patterns) {
if !expected_errors.is_empty() {
if !props.error_patterns.is_empty() {
fatal(~"both error pattern and expected errors specified");
}
check_expected_errors(expected_errors, testfile, procres);
Expand Down Expand Up @@ -440,7 +440,7 @@ fn compose_and_run_compiler(
args: procargs,
input: Option<~str>) -> procres {

if props.aux_builds.is_not_empty() {
if !props.aux_builds.is_empty() {
ensure_dir(&aux_output_dir_name(config, testfile));
}

Expand Down
3 changes: 2 additions & 1 deletion src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ pub use path::PosixPath;

pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use str::{StrSlice, Trimmable};
pub use vec::{ConstVector, CopyableVector, ImmutableVector};
pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
Expand Down
4 changes: 0 additions & 4 deletions src/libcore/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ impl<T> DList<T> {
pure fn len(@self) -> uint { self.size }
/// Returns true if the list is empty. O(1).
pure fn is_empty(@self) -> bool { self.len() == 0 }
/// Returns true if the list is not empty. O(1).
pure fn is_not_empty(@self) -> bool { self.len() != 0 }

/// Add data to the head of the list. O(1).
fn push_head(@self, data: T) {
Expand Down Expand Up @@ -648,8 +646,6 @@ mod tests {
let full1 = from_vec(~[1,2,3]);
assert empty.is_empty();
assert !full1.is_empty();
assert !empty.is_not_empty();
assert full1.is_not_empty();
}
#[test]
fn test_dlist_head_tail() {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub pure fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {

// turn digits into string
// using stack of digits
while fractionalParts.is_not_empty() {
while !fractionalParts.is_empty() {
// Bleh; shouldn't need to be unsafe
let mut adjusted_digit = carry + unsafe { fractionalParts.pop() };

Expand Down
3 changes: 2 additions & 1 deletion src/libcore/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub use path::PosixPath;

pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use str::{StrSlice, Trimmable};
pub use vec::{ConstVector, CopyableVector, ImmutableVector};
pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
Expand Down
13 changes: 0 additions & 13 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,6 @@ pub pure fn is_ascii(s: &str) -> bool {
/// Returns true if the string has length 0
pub pure fn is_empty(s: &str) -> bool { len(s) == 0u }

/// Returns true if the string has length greater than 0
pub pure fn is_not_empty(s: &str) -> bool { !is_empty(s) }

/**
* Returns true if the string contains only whitespace
*
Expand Down Expand Up @@ -2167,7 +2164,6 @@ pub trait StrSlice {
pure fn each_chari(it: fn(uint, char) -> bool);
pure fn ends_with(needle: &str) -> bool;
pure fn is_empty() -> bool;
pure fn is_not_empty() -> bool;
pure fn is_whitespace() -> bool;
pure fn is_alphanumeric() -> bool;
pure fn len() -> uint;
Expand Down Expand Up @@ -2229,9 +2225,6 @@ impl &str: StrSlice {
/// Returns true if the string has length 0
#[inline]
pure fn is_empty() -> bool { is_empty(self) }
/// Returns true if the string has length greater than 0
#[inline]
pure fn is_not_empty() -> bool { is_not_empty(self) }
/**
* Returns true if the string contains only whitespace
*
Expand Down Expand Up @@ -2739,12 +2732,6 @@ mod tests {
assert (!is_empty(~"a"));
}

#[test]
fn test_is_not_empty() {
assert (is_not_empty(~"a"));
assert (!is_not_empty(~""));
}

#[test]
fn test_replace() {
let a = ~"a";
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ terminate normally, but instead directly return from a function.
~~~
fn choose_weighted_item(v: &[Item]) -> Item {
assert v.is_not_empty();
assert !v.is_empty();
let mut so_far = 0u;
for v.each |item| {
so_far += item.weight;
Expand Down
40 changes: 17 additions & 23 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#[forbid(deprecated_pattern)];
#[warn(non_camel_case_types)];

use container::{Container, Mutable};
use cast::transmute;
use cast;
use cmp::{Eq, Ord};
Expand Down Expand Up @@ -48,11 +49,6 @@ pub pure fn is_empty<T>(v: &[const T]) -> bool {
as_const_buf(v, |_p, len| len == 0u)
}

/// Returns true if a vector contains some elements
pub pure fn is_not_empty<T>(v: &[const T]) -> bool {
as_const_buf(v, |_p, len| len > 0u)
}

/// Returns true if two vectors have the same length
pub pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool {
len(xs) == len(ys)
Expand Down Expand Up @@ -453,7 +449,7 @@ pub pure fn partitioned<T: Copy>(v: &[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
/// Removes the first element from a vector and return it
pub fn shift<T>(v: &mut ~[T]) -> T {
unsafe {
assert v.is_not_empty();
assert !v.is_empty();

if v.len() == 1 { return v.pop() }

Expand Down Expand Up @@ -1647,20 +1643,11 @@ pub mod traits {
}
}

pub trait ConstVector {
pure fn is_empty(&self) -> bool;
pure fn is_not_empty(&self) -> bool;
pure fn len(&self) -> uint;
}

/// Extension methods for vectors
impl<T> &[const T]: ConstVector {
impl<T> &[const T]: Container {
/// Returns true if a vector contains no elements
#[inline]
pure fn is_empty(&self) -> bool { is_empty(*self) }
/// Returns true if a vector contains some elements
#[inline]
pure fn is_not_empty(&self) -> bool { is_not_empty(*self) }

/// Returns the length of a vector
#[inline]
pure fn len(&self) -> uint { len(*self) }
Expand Down Expand Up @@ -1949,6 +1936,11 @@ impl<T> ~[T]: OwnedVector<T> {
}
}

impl<T> ~[T]: Mutable {
/// Clear the vector, removing all values.
fn clear(&mut self) { self.truncate(0) }
}

pub trait OwnedCopyableVector<T: Copy> {
fn push_all(&mut self, rhs: &[const T]);
fn grow(&mut self, n: uint, initval: &T);
Expand Down Expand Up @@ -2518,12 +2510,6 @@ mod tests {
assert (!is_empty(~[0]));
}

#[test]
fn test_is_not_empty() {
assert (is_not_empty(~[0]));
assert (!is_not_empty::<int>(~[]));
}

#[test]
fn test_len_divzero() {
type Z = [i8 * 0];
Expand Down Expand Up @@ -2700,6 +2686,14 @@ mod tests {
// If the unsafe block didn't drop things properly, we blow up here.
}

#[test]
fn test_clear() {
let mut v = ~[@6,@5,@4];
v.clear();
assert(v.len() == 0);
// If the unsafe block didn't drop things properly, we blow up here.
}

#[test]
fn test_dedup() {
fn case(a: ~[uint], b: ~[uint]) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {

path.push_all(vec::view(split2, start_idx, len2 - 1));

if vec::is_not_empty(path) {
if !path.is_empty() {
return Path("").push_many(path);
} else {
return Path(".");
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) ->
}

fn is_test_fn(i: @ast::item) -> bool {
let has_test_attr = attr::find_attrs_by_name(i.attrs,
~"test").is_not_empty();
let has_test_attr = !attr::find_attrs_by_name(i.attrs,
~"test").is_empty();

fn has_test_signature(i: @ast::item) -> bool {
match &i.node {
Expand All @@ -171,7 +171,7 @@ fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool {
let ignoreitems = attr::attr_metas(ignoreattrs);
let cfg_metas = vec::concat(vec::filter_map(ignoreitems,
|i| attr::get_meta_item_list(*i)));
return if vec::is_not_empty(ignoreitems) {
return if !ignoreitems.is_empty() {
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ fn type_to_str_inner(names: type_names, +outer0: ~[TypeRef], ty: TypeRef) ->
Struct => {
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
let mut elts = vec::from_elem(n_elts, 0 as TypeRef);
if elts.is_not_empty() {
if !elts.is_empty() {
llvm::LLVMGetStructElementTypes(
ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn warn_if_multiple_versions(e: env, diag: span_handler,
}
}));

assert matches.is_not_empty();
assert !matches.is_empty();

if matches.len() != 1u {
diag.handler().warn(
Expand Down Expand Up @@ -168,7 +168,7 @@ fn visit_item(e: env, i: @ast::item) {
already_added = !cstore::add_used_library(cstore,
foreign_name);
}
if link_args.is_not_empty() && already_added {
if !link_args.is_empty() && already_added {
e.diag.span_fatal(i.span, ~"library '" + foreign_name +
~"' already added: can't specify link_args.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,8 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: &crate) -> ~[attribute] {
fn synthesize_link_attr(ecx: @encode_ctxt, +items: ~[@meta_item]) ->
attribute {

assert ecx.link_meta.name.is_not_empty();
assert ecx.link_meta.vers.is_not_empty();
assert !ecx.link_meta.name.is_empty();
assert !ecx.link_meta.vers.is_empty();

let name_item =
attr::mk_name_value_item_str(~"name",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn crate_matches(crate_data: @~[u8], +metas: ~[@ast::meta_item],
hash: ~str) -> bool {
let attrs = decoder::get_crate_attributes(crate_data);
let linkage_metas = attr::find_linkage_metas(attrs);
if hash.is_not_empty() {
if !hash.is_empty() {
let chash = decoder::get_crate_hash(crate_data);
if chash != hash { return false; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn raw_pat(p: @pat) -> @pat {
}

fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
assert(pats.is_not_empty());
assert(!pats.is_empty());
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
not_useful => return, // This is good, wildcard pattern isn't reachable
useful_ => None,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
let ident = cx.sess.str_of(ident);
assert ident.is_not_empty();
assert !ident.is_empty();
let ident = ident_without_trailing_underscores(ident);
let ident = ident_without_leading_underscores(ident);
char::is_uppercase(str::char_at(ident, 0)) &&
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
parent_id: ast::def_id, substs: ~[ty::t])
-> ValueRef {
let _icx = ccx.insn_ctxt("trans_res_dtor");
if (substs.is_not_empty()) {
if !substs.is_empty() {
let did = if did.crate != ast::local_crate {
inline::maybe_instantiate_inline(ccx, did, true)
} else { did };
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
} else {
for m.items.each |item| {
let tpt = ty::lookup_item_type(ccx.tcx, local_def(item.id));
if (*tpt.bounds).is_not_empty() {
if !tpt.bounds.is_empty() {
ccx.tcx.sess.span_err(
item.span,
fmt!("foreign items may not have type parameters"));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
Some(ast_map::node_item(it,_)) => {
match it.node {
ast::item_fn(_, _, ref ps, _)
if vec::is_not_empty(*ps) => {
if !ps.is_empty() => {
tcx.sess.span_err(
main_span,
~"main function is not allowed \
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/attr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn parse_hidden(+attrs: ~[ast::attribute]) -> bool {
match attr::get_meta_item_list(*meta) {
Some(metas) => {
let hiddens = attr::find_meta_items_by_name(metas, ~"hidden");
vec::is_not_empty(hiddens)
!hiddens.is_empty()
}
None => false
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/desc_to_brief_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn parse_desc(desc: ~str) -> Option<~str> {

fn first_sentence(s: ~str) -> Option<~str> {
let paras = paragraphs(s);
if vec::is_not_empty(paras) {
if !paras.is_empty() {
let first_para = vec::head(paras);
Some(str::replace(first_sentence_(first_para), ~"\n", ~" "))
} else {
Expand Down Expand Up @@ -193,7 +193,7 @@ fn paragraphs(s: ~str) -> ~[~str] {
whitespace_lines += 1;
} else {
if whitespace_lines > 0 {
if str::is_not_empty(accum) {
if !accum.is_empty() {
res += ~[accum];
accum = ~"";
}
Expand All @@ -211,7 +211,7 @@ fn paragraphs(s: ~str) -> ~[~str] {
res
};

if str::is_not_empty(accum) {
if !accum.is_empty() {
paras + ~[accum]
} else {
paras
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/unindent_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn unindent(s: ~str) -> ~str {
}
};

if vec::is_not_empty(lines) {
if !lines.is_empty() {
let unindented = ~[str::trim(vec::head(lines))]
+ do par::map(vec::tail(lines)) |line| {
if str::is_whitespace(*line) {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub impl BigUint {
}

pure fn is_zero(&self) -> bool { self.data.is_empty() }
pure fn is_not_zero(&self) -> bool { self.data.is_not_empty() }
pure fn is_not_zero(&self) -> bool { !self.data.is_empty() }
pure fn is_positive(&self) -> bool { self.is_not_zero() }
pure fn is_negative(&self) -> bool { false }
pure fn is_nonpositive(&self) -> bool { self.is_zero() }
Expand Down
Loading

0 comments on commit 85a34c2

Please sign in to comment.