| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
| 6 // Default implementation of a stream with a controller for adding | 6 // Default implementation of a stream with a controller for adding |
| 7 // events to the stream. | 7 // events to the stream. |
| 8 // ------------------------------------------------------------------- | 8 // ------------------------------------------------------------------- |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 if (handleDone == null) handleDone = StreamController._nullDoneHandler; | 403 if (handleDone == null) handleDone = StreamController._nullDoneHandler; |
| 404 _onDone = handleDone; | 404 _onDone = handleDone; |
| 405 } | 405 } |
| 406 | 406 |
| 407 void unsubscribe() { _controller._removeSubscription(this); } | 407 void unsubscribe() { _controller._removeSubscription(this); } |
| 408 | 408 |
| 409 void pause(Signal resume) { _controller._pause(this, resume); } | 409 void pause(Signal resume) { _controller._pause(this, resume); } |
| 410 } | 410 } |
| 411 | 411 |
| 412 /** Helper class for [ControllerSubcription] to store pending subscriptions. */ | 412 /** Helper class for [ControllerSubcription] to store pending subscriptions. */ |
| 413 class _PendingSubscriptionChanges implements _InternalLinkList { | 413 class _PendingSubscriptionChanges extends _InternalLinkList { |
| 414 List<_ControllerSubscription> pendingRemoves; | 414 List<_ControllerSubscription> pendingRemoves; |
| 415 | 415 |
| 416 /** Add a pending subscription. */ | 416 /** Add a pending subscription. */ |
| 417 void addSubscription(_ControllerSubscription subscription) { | 417 void addSubscription(_ControllerSubscription subscription) { |
| 418 assert(_InternalLink.isUnlinked(subscription)); | 418 assert(_InternalLink.isUnlinked(subscription)); |
| 419 _InternalLinkList.add(this, subscription); | 419 _InternalLinkList.add(this, subscription); |
| 420 } | 420 } |
| 421 | 421 |
| 422 /** Add a pending unsubscription. */ | 422 /** Add a pending unsubscription. */ |
| 423 void removeSubscription(_ControllerSubscription subscription) { | 423 void removeSubscription(_ControllerSubscription subscription) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 * An element is considered part of a list if it is in the list's cycle. | 531 * An element is considered part of a list if it is in the list's cycle. |
| 532 * There should never be more than one "list" object in a cycle. | 532 * There should never be more than one "list" object in a cycle. |
| 533 */ | 533 */ |
| 534 abstract class _InternalLinkList extends _InternalLink { | 534 abstract class _InternalLinkList extends _InternalLink { |
| 535 /** | 535 /** |
| 536 * Adds an element to a list, just before the header link. | 536 * Adds an element to a list, just before the header link. |
| 537 * | 537 * |
| 538 * This effectively adds it at the end of the list. | 538 * This effectively adds it at the end of the list. |
| 539 */ | 539 */ |
| 540 static void add(_InternalLinkList list, _InternalLink element) { | 540 static void add(_InternalLinkList list, _InternalLink element) { |
| 541 if (!_InternalLink.isUnlinked(element)) _InternalLink._unlink(element); | 541 if (!_InternalLink.isUnlinked(element)) _InternalLink.unlink(element); |
| 542 _InternalLink listEnd = list._previousLink; | 542 _InternalLink listEnd = list._previousLink; |
| 543 listEnd._nextLink = element; | 543 listEnd._nextLink = element; |
| 544 list._previousLink = element; | 544 list._previousLink = element; |
| 545 element._previousLink = listEnd; | 545 element._previousLink = listEnd; |
| 546 element._nextLink = list; | 546 element._nextLink = list; |
| 547 } | 547 } |
| 548 | 548 |
| 549 /** Removes an element from its list. */ | 549 /** Removes an element from its list. */ |
| 550 static void remove(_InternalLink element) { | 550 static void remove(_InternalLink element) { |
| 551 _InternalLink.unlink(element); | 551 _InternalLink.unlink(element); |
| 552 } | 552 } |
| 553 | 553 |
| 554 /** Check whether a list contains no elements, only the header link. */ | 554 /** Check whether a list contains no elements, only the header link. */ |
| 555 static bool isEmpty(_InternalLinkList list) => _InternalLink.isUnlinked(list); | 555 static bool isEmpty(_InternalLinkList list) => _InternalLink.isUnlinked(list); |
| 556 | 556 |
| 557 /** Moves all elements from the list [other] to [list]. */ | 557 /** Moves all elements from the list [other] to [list]. */ |
| 558 static void addAll(InternalLinkList list, InternalLinkList other) { | 558 static void addAll(_InternalLinkList list, _InternalLinkList other) { |
| 559 if (isEmpty(other)) return; | 559 if (isEmpty(other)) return; |
| 560 if (isEmpty(list)) { | 560 if (isEmpty(list)) { |
| 561 list._nextLink = other._nextLink; | 561 list._nextLink = other._nextLink; |
| 562 list._previousLink = other._previousLink; | 562 list._previousLink = other._previousLink; |
| 563 list._nextLink._previousLink = list; |
| 564 list._previousLink._nextLink = list; |
| 563 } else { | 565 } else { |
| 564 _InternalLink listLast = list._previousLink; | 566 _InternalLink listLast = list._previousLink; |
| 565 _InternalLink otherNext = other._nextLink; | 567 _InternalLink otherNext = other._nextLink; |
| 566 listLast._nextLink = otherNext; | 568 listLast._nextLink = otherNext; |
| 567 otherNext._previousLink = listLast; | 569 otherNext._previousLink = listLast; |
| 568 _InternalLink otherLast = other._previousLink; | 570 _InternalLink otherLast = other._previousLink; |
| 569 list._previousLink = otherLast; | 571 list._previousLink = otherLast; |
| 570 otherLast._nextLink = list; | 572 otherLast._nextLink = list; |
| 571 } | 573 } |
| 572 other._nextLink = other._previousLink = other; | 574 other._nextLink = other._previousLink = other; |
| 573 } | 575 } |
| 574 } | 576 } |
| OLD | NEW |