Skip to content

Commit b6bde88

Browse files
committed
core: Use less code for option dancing that notification channel
1 parent 84c8549 commit b6bde88

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

src/libcore/task.rs

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use cmp::Eq;
3232
use result::Result;
3333
use pipes::{stream, Chan, Port};
3434
use local_data_priv::{local_get, local_set};
35+
use util::replace;
3536

3637
use rt::task_id;
3738
use rt::rust_task;
@@ -246,11 +247,7 @@ priv impl TaskBuilder {
246247
fail ~"Cannot copy a task_builder"; // Fake move mode on self
247248
}
248249
self.consumed = true;
249-
let notify_chan = if self.opts.notify_chan.is_none() {
250-
None
251-
} else {
252-
Some(option::swap_unwrap(&mut self.opts.notify_chan))
253-
};
250+
let notify_chan = replace(&mut self.opts.notify_chan, None);
254251
TaskBuilder({
255252
opts: {
256253
linked: self.opts.linked,
@@ -271,11 +268,7 @@ impl TaskBuilder {
271268
* the other will not be killed.
272269
*/
273270
fn unlinked() -> TaskBuilder {
274-
let notify_chan = if self.opts.notify_chan.is_none() {
275-
None
276-
} else {
277-
Some(option::swap_unwrap(&mut self.opts.notify_chan))
278-
};
271+
let notify_chan = replace(&mut self.opts.notify_chan, None);
279272
TaskBuilder({
280273
opts: {
281274
linked: false,
@@ -293,11 +286,7 @@ impl TaskBuilder {
293286
* the child.
294287
*/
295288
fn supervised() -> TaskBuilder {
296-
let notify_chan = if self.opts.notify_chan.is_none() {
297-
None
298-
} else {
299-
Some(option::swap_unwrap(&mut self.opts.notify_chan))
300-
};
289+
let notify_chan = replace(&mut self.opts.notify_chan, None);
301290
TaskBuilder({
302291
opts: {
303292
linked: false,
@@ -314,11 +303,7 @@ impl TaskBuilder {
314303
* other will be killed.
315304
*/
316305
fn linked() -> TaskBuilder {
317-
let notify_chan = if self.opts.notify_chan.is_none() {
318-
None
319-
} else {
320-
Some(option::swap_unwrap(&mut self.opts.notify_chan))
321-
};
306+
let notify_chan = replace(&mut self.opts.notify_chan, None);
322307
TaskBuilder({
323308
opts: {
324309
linked: true,
@@ -381,11 +366,7 @@ impl TaskBuilder {
381366
}
382367
/// Configure a custom scheduler mode for the task.
383368
fn sched_mode(mode: SchedMode) -> TaskBuilder {
384-
let notify_chan = if self.opts.notify_chan.is_none() {
385-
None
386-
} else {
387-
Some(option::swap_unwrap(&mut self.opts.notify_chan))
388-
};
369+
let notify_chan = replace(&mut self.opts.notify_chan, None);
389370
TaskBuilder({
390371
opts: {
391372
linked: self.opts.linked,
@@ -412,11 +393,7 @@ impl TaskBuilder {
412393
*/
413394
fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder {
414395
let prev_gen_body = self.gen_body;
415-
let notify_chan = if self.opts.notify_chan.is_none() {
416-
None
417-
} else {
418-
Some(option::swap_unwrap(&mut self.opts.notify_chan))
419-
};
396+
let notify_chan = replace(&mut self.opts.notify_chan, None);
420397
TaskBuilder({
421398
opts: {
422399
linked: self.opts.linked,
@@ -447,13 +424,7 @@ impl TaskBuilder {
447424
* must be greater than zero.
448425
*/
449426
fn spawn(f: fn~()) {
450-
let notify_chan = if self.opts.notify_chan.is_none() {
451-
None
452-
} else {
453-
let swapped_notify_chan =
454-
option::swap_unwrap(&mut self.opts.notify_chan);
455-
Some(move swapped_notify_chan)
456-
};
427+
let notify_chan = replace(&mut self.opts.notify_chan, None);
457428
let x = self.consume();
458429
let opts = {
459430
linked: x.opts.linked,

0 commit comments

Comments
 (0)