Rename option::get_default => get_or_default, get_zero => get_or_zero

This commit is contained in:
Tim Chevalier 2013-01-04 16:01:26 -08:00
parent 4d8cc3f003
commit 89acd1f57f
11 changed files with 20 additions and 20 deletions

View File

@ -100,7 +100,7 @@ pub pure fn build<A>(builder: &fn(push: pure fn(v: A))) -> @[A] {
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: pure fn(v: A))) -> @[A] {
build_sized(size.get_default(4), builder)
build_sized(size.get_or_default(4), builder)
}
// Appending

View File

@ -267,7 +267,7 @@ pub pure fn build_sized_opt<A,B: Buildable<A>>(
size: Option<uint>,
builder: fn(push: pure fn(A))) -> B {
Buildable::build_sized(size.get_default(4), builder)
Buildable::build_sized(size.get_or_default(4), builder)
}
// Functions that combine iteration and building

View File

@ -171,13 +171,13 @@ pub pure fn is_some<T>(opt: &Option<T>) -> bool {
!is_none(opt)
}
pub pure fn get_zero<T: Copy Zero>(opt: Option<T>) -> T {
pub pure fn get_or_zero<T: Copy Zero>(opt: Option<T>) -> T {
//! Returns the contained value or zero (for this type)
match opt { Some(copy x) => x, None => Zero::zero() }
}
pub pure fn get_default<T: Copy>(opt: Option<T>, def: T) -> T {
pub pure fn get_or_default<T: Copy>(opt: Option<T>, def: T) -> T {
//! Returns the contained value or a default
match opt { Some(copy x) => x, None => def }
@ -331,7 +331,7 @@ impl<T: Copy> Option<T> {
pure fn get(self) -> T { get(self) }
#[inline(always)]
pure fn get_default(self, def: T) -> T { get_default(self, def) }
pure fn get_or_default(self, def: T) -> T { get_or_default(self, def) }
/// Applies a function zero or more times until the result is none.
#[inline(always)]
@ -342,7 +342,7 @@ impl<T: Copy> Option<T> {
impl<T: Copy Zero> Option<T> {
#[inline(always)]
pure fn get_zero(self) -> T { get_zero(self) }
pure fn get_or_zero(self) -> T { get_or_zero(self) }
}
#[test]
@ -420,11 +420,11 @@ fn test_option_while_some() {
}
#[test]
fn test_get_zero() {
fn test_get_or_zero() {
let some_stuff = Some(42);
assert some_stuff.get_zero() == 42;
assert some_stuff.get_or_zero() == 42;
let no_stuff: Option<int> = None;
assert no_stuff.get_zero() == 0;
assert no_stuff.get_or_zero() == 0;
}
// Local Variables:

View File

@ -510,14 +510,14 @@ pub fn tmpdir() -> Path {
#[cfg(unix)]
#[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path {
option::get_default(getenv_nonempty("TMPDIR"),
option::get_or_default(getenv_nonempty("TMPDIR"),
Path("/tmp"))
}
#[cfg(windows)]
#[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path {
option::get_default(
option::get_or_default(
option::or(getenv_nonempty("TMP"),
option::or(getenv_nonempty("TEMP"),
option::or(getenv_nonempty("USERPROFILE"),

View File

@ -203,7 +203,7 @@ pub pure fn build<A>(builder: fn(push: pure fn(v: A))) -> ~[A] {
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: fn(push: pure fn(v: A))) -> ~[A] {
build_sized(size.get_default(4), builder)
build_sized(size.get_or_default(4), builder)
}
/// Produces a mut vector from an immutable vector.

View File

@ -113,7 +113,7 @@ fn make_target_lib_path(sysroot: &Path,
sysroot.push_rel(&relative_target_lib_path(target_triple))
}
fn get_default_sysroot() -> Path {
fn get_or_default_sysroot() -> Path {
match os::self_exe_path() {
option::Some(ref p) => (*p).pop(),
option::None => fail ~"can't determine value for sysroot"
@ -123,12 +123,12 @@ fn get_default_sysroot() -> Path {
fn get_sysroot(maybe_sysroot: Option<Path>) -> Path {
match maybe_sysroot {
option::Some(ref sr) => (*sr),
option::None => get_default_sysroot()
option::None => get_or_default_sysroot()
}
}
fn get_cargo_sysroot() -> Result<Path, ~str> {
result::Ok(get_default_sysroot().push_many([libdir(), ~"cargo"]))
result::Ok(get_or_default_sysroot().push_many([libdir(), ~"cargo"]))
}
fn get_cargo_root() -> Result<Path, ~str> {

View File

@ -502,7 +502,7 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
match p.node {
ast::pat_enum(_, subpats) => {
if opt_eq(tcx, &variant_opt(tcx, p.id), opt) {
Some(option::get_default(subpats,
Some(option::get_or_default(subpats,
vec::from_elem(variant_size,
dummy)))
} else {

View File

@ -136,7 +136,7 @@ fn monomorphic_fn(ccx: @crate_ctxt,
ccx.stats.n_monos += 1;
let depth = option::get_default(ccx.monomorphizing.find(fn_id), 0u);
let depth = option::get_or_default(ccx.monomorphizing.find(fn_id), 0u);
// Random cut-off -- code that needs to instantiate the same function
// recursively more than ten times can probably safely be assumed to be
// causing an infinite expansion.

View File

@ -69,7 +69,7 @@ fn fold_crate(
{
topmod: doc::ModDoc_({
item: {
name: option::get_default(attrs.name, doc.topmod.name()),
name: option::get_or_default(attrs.name, doc.topmod.name()),
.. doc.topmod.item
},
.. *doc.topmod

View File

@ -154,7 +154,7 @@ fn config_from_opts(
let output_dir = getopts::opt_maybe_str(matches, opt_output_dir());
let output_dir = output_dir.map(|s| Path(*s));
result::Ok({
output_dir: output_dir.get_default(config.output_dir),
output_dir: output_dir.get_or_default(config.output_dir),
.. config
})
};

View File

@ -83,7 +83,7 @@ fn strip_doc_comment_decoration(comment: ~str) -> ~str {
// drop leftmost columns that contain only values in chars
fn block_trim(lines: ~[~str], chars: ~str, max: Option<uint>) -> ~[~str] {
let mut i = max.get_default(uint::max_value);
let mut i = max.get_or_default(uint::max_value);
for lines.each |line| {
if line.trim().is_empty() {
loop;