提交 89acd1f5 编写于 作者: T Tim Chevalier

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

上级 4d8cc3f0
......@@ -100,7 +100,7 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
#[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
......
......@@ -267,7 +267,7 @@ pub trait 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
......
......@@ -171,13 +171,13 @@ pub enum Option<T> {
!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:
......
......@@ -510,14 +510,14 @@ fn getenv_nonempty(v: &str) -> Option<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"),
......
......@@ -203,7 +203,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
#[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.
......
......@@ -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> {
......
......@@ -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 {
......
......@@ -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.
......
......@@ -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
......
......@@ -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
})
};
......
......@@ -83,7 +83,7 @@ fn vertical_trim(lines: ~[~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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册