Skip to content

Rename Option swap_unwrap to take_unwrap. #7831

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

Merged
merged 1 commit into from
Jul 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ impl<T> Deque<T> for DList<T> {
let tail_own = match tail.prev.resolve() {
None => {
self.list_tail = Rawlink::none();
self.list_head.swap_unwrap()
self.list_head.take_unwrap()
},
Some(tail_prev) => {
self.list_tail = tail.prev;
tail_prev.next.swap_unwrap()
tail_prev.next.take_unwrap()
}
};
Some(tail_own.value)
Expand Down Expand Up @@ -465,7 +465,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
Some(prev) => prev,
};
let mut ins_node = ~Node{value: elt, next: None, prev: Rawlink::none()};
let node_own = prev_node.next.swap_unwrap();
let node_own = prev_node.next.take_unwrap();
ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
self.list.length += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn get_addr(node: &str, iotask: &iotask)
let (output_po, output_ch) = stream();
let mut output_ch = Some(SharedChan::new(output_ch));
do str::as_buf(node) |node_ptr, len| {
let output_ch = output_ch.swap_unwrap();
let output_ch = output_ch.take_unwrap();
debug!("slice len %?", len);
let handle = create_uv_getaddrinfo_t();
let handle_ptr: *uv_getaddrinfo_t = &handle;
Expand Down
8 changes: 4 additions & 4 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<'self> Condvar<'self> {
signal_waitqueue(&state.waiters);
}
// Enqueue ourself to be woken up by a signaller.
let SignalEnd = SignalEnd.swap_unwrap();
let SignalEnd = SignalEnd.take_unwrap();
state.blocked[condvar_id].tail.send(SignalEnd);
} else {
out_of_bounds = Some(state.blocked.len());
Expand All @@ -281,7 +281,7 @@ impl<'self> Condvar<'self> {
// Unconditionally "block". (Might not actually block if a
// signaller already sent -- I mean 'unconditionally' in contrast
// with acquire().)
let _ = comm::recv_one(WaitEnd.swap_unwrap());
let _ = comm::recv_one(WaitEnd.take_unwrap());
}

// This is needed for a failing condition variable to reacquire the
Expand Down Expand Up @@ -353,7 +353,7 @@ impl<'self> Condvar<'self> {
}
}
do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") {
let queue = queue.swap_unwrap();
let queue = queue.take_unwrap();
broadcast_waitqueue(&queue)
}
}
Expand Down Expand Up @@ -1436,7 +1436,7 @@ mod tests {
do x.write_downgrade |xwrite| {
let mut xopt = Some(xwrite);
do y.write_downgrade |_ywrite| {
y.downgrade(xopt.swap_unwrap());
y.downgrade(xopt.take_unwrap());
error!("oops, y.downgrade(x) should have failed!");
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
// Remove left horizontal link by rotating right
fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
if node.left.map_default(false, |x| x.level == node.level) {
let mut save = node.left.swap_unwrap();
let mut save = node.left.take_unwrap();
swap(&mut node.left, &mut save.right); // save.right now None
swap(node, &mut save);
node.right = Some(save);
Expand All @@ -564,7 +564,7 @@ fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
fn split<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
if node.right.map_default(false,
|x| x.right.map_default(false, |y| y.level == node.level)) {
let mut save = node.right.swap_unwrap();
let mut save = node.right.take_unwrap();
swap(&mut node.right, &mut save.left); // save.left now None
save.level += 1;
swap(node, &mut save);
Expand Down Expand Up @@ -643,7 +643,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
Equal => {
if save.left.is_some() {
if save.right.is_some() {
let mut left = save.left.swap_unwrap();
let mut left = save.left.take_unwrap();
if left.right.is_some() {
heir_swap(save, &mut left.right);
} else {
Expand All @@ -653,13 +653,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
save.left = Some(left);
(remove(&mut save.left, key), true)
} else {
let new = save.left.swap_unwrap();
let new = save.left.take_unwrap();
let ~TreeNode{value, _} = replace(save, new);
*save = save.left.swap_unwrap();
*save = save.left.take_unwrap();
(Some(value), true)
}
} else if save.right.is_some() {
let new = save.right.swap_unwrap();
let new = save.right.take_unwrap();
let ~TreeNode{value, _} = replace(save, new);
(Some(value), true)
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ impl<T> Option<T> {
/// Apply a function to the contained value or do nothing
pub fn mutate(&mut self, f: &fn(T) -> T) {
if self.is_some() {
*self = Some(f(self.swap_unwrap()));
*self = Some(f(self.take_unwrap()));
}
}

/// 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) {
if self.is_some() {
*self = Some(f(self.swap_unwrap()));
*self = Some(f(self.take_unwrap()));
} else {
*self = Some(def);
}
Expand Down Expand Up @@ -293,8 +293,8 @@ impl<T> Option<T> {
* Fails if the value equals `None`.
*/
#[inline]
pub fn swap_unwrap(&mut self) -> T {
if self.is_none() { fail!("option::swap_unwrap none") }
pub fn take_unwrap(&mut self) -> T {
if self.is_none() { fail!("option::take_unwrap none") }
util::replace(self, None).unwrap()
}

Expand Down Expand Up @@ -460,16 +460,16 @@ fn test_option_dance() {
let mut y = Some(5);
let mut y2 = 0;
for x.iter().advance |_x| {
y2 = y.swap_unwrap();
y2 = y.take_unwrap();
}
assert_eq!(y2, 5);
assert!(y.is_none());
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() {
let mut y = Some(util::NonCopyable);
let _y2 = y.swap_unwrap();
let _y3 = y.swap_unwrap();
let _y2 = y.take_unwrap();
let _y3 = y.take_unwrap();
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/rt/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Scheduler {
/// Given an input Coroutine sends it back to its home scheduler.
fn send_task_home(task: ~Task) {
let mut task = task;
let mut home = task.home.swap_unwrap();
let mut home = task.home.take_unwrap();
match home {
Sched(ref mut home_handle) => {
home_handle.send(PinnedTask(task));
Expand Down Expand Up @@ -418,7 +418,7 @@ impl Scheduler {

do self.deschedule_running_task_and_then |sched, dead_task| {
let mut dead_task = dead_task;
let coroutine = dead_task.coroutine.swap_unwrap();
let coroutine = dead_task.coroutine.take_unwrap();
coroutine.recycle(&mut sched.stack_pool);
}

Expand Down Expand Up @@ -506,7 +506,7 @@ impl Scheduler {
this.metrics.context_switches_task_to_sched += 1;

unsafe {
let blocked_task = this.current_task.swap_unwrap();
let blocked_task = this.current_task.take_unwrap();
let f_fake_region = transmute::<&fn(&mut Scheduler, ~Task),
&fn(&mut Scheduler, ~Task)>(f);
let f_opaque = ClosureConverter::from_fn(f_fake_region);
Expand Down Expand Up @@ -538,7 +538,7 @@ impl Scheduler {
rtdebug!("switching tasks");
this.metrics.context_switches_task_to_task += 1;

let old_running_task = this.current_task.swap_unwrap();
let old_running_task = this.current_task.take_unwrap();
let f_fake_region = unsafe {
transmute::<&fn(&mut Scheduler, ~Task),
&fn(&mut Scheduler, ~Task)>(f)
Expand Down Expand Up @@ -576,7 +576,7 @@ impl Scheduler {

assert!(self.cleanup_job.is_some());

let cleanup_job = self.cleanup_job.swap_unwrap();
let cleanup_job = self.cleanup_job.take_unwrap();
match cleanup_job {
DoNothing => { }
GiveTask(task, f) => (f.to_fn())(self, task)
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Task {

// Wait for children. Possibly report the exit status.
let local_success = !self.unwinder.unwinding;
let join_latch = self.join_latch.swap_unwrap();
let join_latch = self.join_latch.take_unwrap();
match self.on_exit {
Some(ref on_exit) => {
let success = join_latch.wait(local_success);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/tube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<T> Tube<T> {
if (*state).blocked_task.is_some() {
// There's a waiting task. Wake it up
rtdebug!("waking blocked tube");
let task = (*state).blocked_task.swap_unwrap();
let task = (*state).blocked_task.take_unwrap();
let sched = Local::take::<Scheduler>();
sched.resume_task_immediately(task);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/uv/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl AsyncWatcher {
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
{
let data = watcher.get_watcher_data();
data.close_cb.swap_unwrap()();
data.close_cb.take_unwrap()();
}
watcher.drop_watcher_data();
unsafe { uvll::free_handle(handle as *c_void); }
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/uv/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl IdleWatcher {
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
{
let data = idle_watcher.get_watcher_data();
data.close_cb.swap_unwrap()();
data.close_cb.take_unwrap()();
}
idle_watcher.drop_watcher_data();
uvll::idle_delete(handle);
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/rt/uv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl StreamWatcher {
let write_request: WriteRequest = NativeHandle::from_native_handle(req);
let mut stream_watcher = write_request.stream();
write_request.delete();
let cb = stream_watcher.get_watcher_data().write_cb.swap_unwrap();
let cb = stream_watcher.get_watcher_data().write_cb.take_unwrap();
let status = status_to_maybe_uv_error(stream_watcher.native_handle(), status);
cb(stream_watcher, status);
}
Expand All @@ -233,7 +233,7 @@ impl StreamWatcher {

extern fn close_cb(handle: *uvll::uv_stream_t) {
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
stream_watcher.get_watcher_data().close_cb.swap_unwrap()();
stream_watcher.get_watcher_data().close_cb.take_unwrap()();
stream_watcher.drop_watcher_data();
unsafe { free_handle(handle as *c_void) }
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl TcpWatcher {
let connect_request: ConnectRequest = NativeHandle::from_native_handle(req);
let mut stream_watcher = connect_request.stream();
connect_request.delete();
let cb = stream_watcher.get_watcher_data().connect_cb.swap_unwrap();
let cb = stream_watcher.get_watcher_data().connect_cb.take_unwrap();
let status = status_to_maybe_uv_error(stream_watcher.native_handle(), status);
cb(stream_watcher, status);
}
Expand Down Expand Up @@ -438,7 +438,7 @@ impl UdpWatcher {
let send_request: UdpSendRequest = NativeHandle::from_native_handle(req);
let mut udp_watcher = send_request.handle();
send_request.delete();
let cb = udp_watcher.get_watcher_data().udp_send_cb.swap_unwrap();
let cb = udp_watcher.get_watcher_data().udp_send_cb.take_unwrap();
let status = status_to_maybe_uv_error(udp_watcher.native_handle(), status);
cb(udp_watcher, status);
}
Expand All @@ -456,7 +456,7 @@ impl UdpWatcher {

extern fn close_cb(handle: *uvll::uv_udp_t) {
let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);
udp_watcher.get_watcher_data().close_cb.swap_unwrap()();
udp_watcher.get_watcher_data().close_cb.take_unwrap()();
udp_watcher.drop_watcher_data();
unsafe { free_handle(handle as *c_void) }
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/uv/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl TimerWatcher {
let mut watcher: TimerWatcher = NativeHandle::from_native_handle(handle);
{
let data = watcher.get_watcher_data();
data.close_cb.swap_unwrap()();
data.close_cb.take_unwrap()();
}
watcher.drop_watcher_data();
unsafe {
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fn each_ancestor(list: &mut AncestorList,
fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>,
blk: &fn(TaskGroupInner) -> U) -> U {
// If this trips, more likely the problem is 'blk' failed inside.
let tmp_arc = parent_group.swap_unwrap();
let tmp_arc = parent_group.take_unwrap();
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
*parent_group = Some(tmp_arc);
result
Expand Down Expand Up @@ -609,7 +609,7 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
};

if opts.notify_chan.is_some() {
let notify_chan = opts.notify_chan.swap_unwrap();
let notify_chan = opts.notify_chan.take_unwrap();
let notify_chan = Cell::new(notify_chan);
let on_exit: ~fn(bool) = |success| {
notify_chan.take().send(
Expand Down Expand Up @@ -647,7 +647,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
let notify_chan = if opts.notify_chan.is_none() {
None
} else {
Some(opts.notify_chan.swap_unwrap())
Some(opts.notify_chan.take_unwrap())
};

let child_wrapper = make_child_wrapper(new_task, child_tg,
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/msgsend-ring-mutex-arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j);
let mut num_chan2 = num_chan.swap_unwrap();
let mut num_port2 = num_port.swap_unwrap();
let mut num_chan2 = num_chan.take_unwrap();
let mut num_port2 = num_port.take_unwrap();
send(&num_chan2, i * j);
num_chan = Some(num_chan2);
let _n = recv(&num_port2);
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/msgsend-ring-rw-arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j);
let mut num_chan2 = num_chan.swap_unwrap();
let mut num_port2 = num_port.swap_unwrap();
let mut num_chan2 = num_chan.take_unwrap();
let mut num_port2 = num_port.take_unwrap();
send(&num_chan2, i * j);
num_chan = Some(num_chan2);
let _n = recv(&num_port2);
Expand Down