@@ -32,6 +32,7 @@ use cmp::Eq;
32
32
use result:: Result ;
33
33
use pipes:: { stream, Chan , Port } ;
34
34
use local_data_priv:: { local_get, local_set} ;
35
+ use util:: replace;
35
36
36
37
use rt:: task_id;
37
38
use rt:: rust_task;
@@ -246,11 +247,7 @@ priv impl TaskBuilder {
246
247
fail ~"Cannot copy a task_builder"; // Fake move mode on self
247
248
}
248
249
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 ) ;
254
251
TaskBuilder ( {
255
252
opts : {
256
253
linked : self . opts . linked ,
@@ -271,11 +268,7 @@ impl TaskBuilder {
271
268
* the other will not be killed.
272
269
*/
273
270
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 ) ;
279
272
TaskBuilder ( {
280
273
opts : {
281
274
linked : false ,
@@ -293,11 +286,7 @@ impl TaskBuilder {
293
286
* the child.
294
287
*/
295
288
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 ) ;
301
290
TaskBuilder ( {
302
291
opts : {
303
292
linked : false ,
@@ -314,11 +303,7 @@ impl TaskBuilder {
314
303
* other will be killed.
315
304
*/
316
305
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 ) ;
322
307
TaskBuilder ( {
323
308
opts : {
324
309
linked : true ,
@@ -381,11 +366,7 @@ impl TaskBuilder {
381
366
}
382
367
/// Configure a custom scheduler mode for the task.
383
368
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);
389
370
TaskBuilder({
390
371
opts: {
391
372
linked: self.opts.linked,
@@ -412,11 +393,7 @@ impl TaskBuilder {
412
393
*/
413
394
fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder {
414
395
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);
420
397
TaskBuilder({
421
398
opts: {
422
399
linked: self.opts.linked,
@@ -447,13 +424,7 @@ impl TaskBuilder {
447
424
* must be greater than zero.
448
425
*/
449
426
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);
457
428
let x = self.consume();
458
429
let opts = {
459
430
linked: x.opts.linked,
0 commit comments