Remove superfluous by-ref in option::get, option::get_default, option::expect

Superficial change, no review.
This commit is contained in:
Tim Chevalier 2012-10-19 11:37:00 -07:00
parent c97944fbf8
commit 10612ee30c
13 changed files with 35 additions and 35 deletions

View File

@ -296,7 +296,7 @@ fn check_variants_T<T: Copy>(
}
fn last_part(filename: ~str) -> ~str {
let ix = option::get(&str::rfind_char(filename, '/'));
let ix = option::get(str::rfind_char(filename, '/'));
str::slice(filename, ix + 1u, str::len(filename) - 3u)
}

View File

@ -208,7 +208,7 @@ impl<T> DList<T> {
fn push_head_n(data: T) -> DListNode<T> {
let mut nobe = self.new_link(move data);
self.add_head(nobe);
option::get(&nobe)
option::get(nobe)
}
/// Add data to the tail of the list. O(1).
fn push(data: T) {
@ -221,7 +221,7 @@ impl<T> DList<T> {
fn push_n(data: T) -> DListNode<T> {
let mut nobe = self.new_link(move data);
self.add_tail(nobe);
option::get(&nobe)
option::get(nobe)
}
/**
* Insert data into the middle of the list, left of the given node.
@ -245,7 +245,7 @@ impl<T> DList<T> {
fn insert_before_n(data: T, neighbour: DListNode<T>) -> DListNode<T> {
let mut nobe = self.new_link(move data);
self.insert_left(nobe, neighbour);
option::get(&nobe)
option::get(nobe)
}
/**
* Insert data into the middle of the list, right of the given node.
@ -269,7 +269,7 @@ impl<T> DList<T> {
fn insert_after_n(data: T, neighbour: DListNode<T>) -> DListNode<T> {
let mut nobe = self.new_link(move data);
self.insert_right(neighbour, nobe);
option::get(&nobe)
option::get(nobe)
}
/// Remove a node from the head of the list. O(1).
@ -385,17 +385,17 @@ impl<T> DList<T> {
let mut link = self.peek_n();
let mut rabbit = link;
while option::is_some(&link) {
let nobe = option::get(&link);
let nobe = option::get(link);
assert nobe.linked;
// check cycle
if option::is_some(&rabbit) {
rabbit = option::get(&rabbit).next;
rabbit = option::get(rabbit).next;
}
if option::is_some(&rabbit) {
rabbit = option::get(&rabbit).next;
rabbit = option::get(rabbit).next;
}
if option::is_some(&rabbit) {
assert !box::ptr_eq(*option::get(&rabbit), *nobe);
assert !box::ptr_eq(*option::get(rabbit), *nobe);
}
// advance
link = nobe.next_link();
@ -406,17 +406,17 @@ impl<T> DList<T> {
link = self.peek_tail_n();
rabbit = link;
while option::is_some(&link) {
let nobe = option::get(&link);
let nobe = option::get(link);
assert nobe.linked;
// check cycle
if option::is_some(&rabbit) {
rabbit = option::get(&rabbit).prev;
rabbit = option::get(rabbit).prev;
}
if option::is_some(&rabbit) {
rabbit = option::get(&rabbit).prev;
rabbit = option::get(rabbit).prev;
}
if option::is_some(&rabbit) {
assert !box::ptr_eq(*option::get(&rabbit), *nobe);
assert !box::ptr_eq(*option::get(rabbit), *nobe);
}
// advance
link = nobe.prev_link();

View File

@ -11,7 +11,7 @@ pub type IMPL_T<A> = dlist::DList<A>;
pub pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
let mut link = self.peek_n();
while option::is_some(&link) {
let nobe = option::get(&link);
let nobe = option::get(link);
assert nobe.linked;
if !f(&nobe.data) { break; }
// Check (weakly) that the user didn't do a remove.

View File

@ -42,7 +42,7 @@ pub enum Option<T> {
Some(T),
}
pub pure fn get<T: Copy>(opt: &Option<T>) -> T {
pub pure fn get<T: Copy>(opt: Option<T>) -> T {
/*!
Gets the value out of an option
@ -58,7 +58,7 @@ pub pure fn get<T: Copy>(opt: &Option<T>) -> T {
case explicitly.
*/
match *opt {
match opt {
Some(copy x) => return x,
None => fail ~"option::get none"
}
@ -85,7 +85,7 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
}
}
pub pure fn expect<T: Copy>(opt: &Option<T>, reason: ~str) -> T {
pub pure fn expect<T: Copy>(opt: Option<T>, reason: ~str) -> T {
/*!
* Gets the value out of an option, printing a specified message on
* failure
@ -94,7 +94,7 @@ pub pure fn expect<T: Copy>(opt: &Option<T>, reason: ~str) -> T {
*
* Fails if the value equals `none`
*/
match *opt { Some(copy x) => x, None => fail reason }
match opt { Some(copy x) => x, None => fail reason }
}
pub pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
@ -167,10 +167,10 @@ pub pure fn is_some<T>(opt: &Option<T>) -> bool {
!is_none(opt)
}
pub pure fn get_default<T: Copy>(opt: &Option<T>, def: T) -> T {
pub pure fn get_default<T: Copy>(opt: Option<T>, def: T) -> T {
//! Returns the contained value or a default
match *opt { Some(copy x) => x, None => def }
match opt { Some(copy x) => x, None => def }
}
pub pure fn map_default<T, U>(opt: &Option<T>, def: U,
@ -284,8 +284,8 @@ impl<T: Copy> Option<T> {
Instead, prefer to use pattern matching and handle the `None`
case explicitly.
*/
pure fn get() -> T { get(&self) }
pure fn get_default(def: T) -> T { get_default(&self, def) }
pure fn get() -> T { get(self) }
pure fn get_default(def: T) -> T { get_default(self, def) }
/**
* Gets the value out of an option, printing a specified message on
* failure
@ -294,7 +294,7 @@ impl<T: Copy> Option<T> {
*
* Fails if the value equals `none`
*/
pure fn expect(reason: ~str) -> T { expect(&self, move reason) }
pure fn expect(reason: ~str) -> T { expect(self, move reason) }
/// Applies a function zero or more times until the result is none.
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
}

View File

@ -473,7 +473,7 @@ pub fn tmpdir() -> Path {
#[cfg(unix)]
#[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path {
option::get_default(&getenv_nonempty("TMPDIR"),
option::get_default(getenv_nonempty("TMPDIR"),
Path("/tmp"))
}

View File

@ -723,7 +723,7 @@ mod tests {
let map = map::HashMap::<~str, ~str>();
assert (option::is_none(&map.find(key)));
map.insert(key, ~"val");
assert (option::get(&map.find(key)) == ~"val");
assert (option::get(map.find(key)) == ~"val");
}
#[test]

View File

@ -353,7 +353,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_default(subpats,
vec::from_elem(variant_size,
dummy)))
} else {

View File

@ -299,7 +299,7 @@ fn trans_static_method_callee(bcx: block,
fn method_from_methods(ms: ~[@ast::method], name: ast::ident)
-> ast::def_id {
local_def(option::get(&vec::find(ms, |m| m.ident == name)).id)
local_def(option::get(vec::find(ms, |m| m.ident == name)).id)
}
fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,

View File

@ -113,7 +113,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_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.
@ -158,7 +158,7 @@ fn monomorphic_fn(ccx: @crate_ctxt,
}
ast_map::node_variant(v, enum_item, _) => {
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
let this_tv = option::get(&vec::find(*tvs, |tv| {
let this_tv = option::get(vec::find(*tvs, |tv| {
tv.id.node == fn_id.node}));
let d = mk_lldecl();
set_inline_hint(d);

View File

@ -57,7 +57,7 @@ impl reflector {
fn visit(ty_name: ~str, args: ~[ValueRef]) {
let tcx = self.bcx.tcx();
let mth_idx = option::get(&ty::method_idx(
let mth_idx = option::get(ty::method_idx(
tcx.sess.ident_of(~"visit_" + ty_name),
*self.visitor_methods));
let mth_ty = ty::mk_fn(tcx, self.visitor_methods[mth_idx].fty);

View File

@ -52,7 +52,7 @@ fn fold_crate(
{
topmod: doc::ModDoc_({
item: {
name: option::get_default(&attrs.name, doc.topmod.name()),
name: option::get_default(attrs.name, doc.topmod.name()),
.. doc.topmod.item
},
.. *doc.topmod
@ -151,7 +151,7 @@ fn fold_enum(
node: ast::item_enum(enum_definition, _), _
}, _) => {
let ast_variant = option::get(
&vec::find(enum_definition.variants, |v| {
vec::find(enum_definition.variants, |v| {
to_str(v.node.name) == variant.name
}));

View File

@ -377,7 +377,7 @@ impl IndexEntry : cmp::Eq {
impl Doc {
fn CrateDoc() -> CrateDoc {
option::get(&vec::foldl(None, self.pages, |_m, page| {
option::get(vec::foldl(None, self.pages, |_m, page| {
match *page {
doc::CratePage(doc) => Some(doc),
_ => None

View File

@ -20,10 +20,10 @@ fn checktests() {
let tests = __test::tests();
let shouldignore = option::get(
&vec::find(tests, |t| t.name == ~"shouldignore" ));
vec::find(tests, |t| t.name == ~"shouldignore" ));
assert shouldignore.ignore == true;
let shouldnotignore = option::get(
&vec::find(tests, |t| t.name == ~"shouldnotignore" ));
vec::find(tests, |t| t.name == ~"shouldnotignore" ));
assert shouldnotignore.ignore == false;
}