Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: tools/dom/src/PathObserver.dart

Issue 16007003: Optimize internals of multiplex-streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Now relative to correct base Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of html; 5 part of html;
6 6
7 // This code is inspired by ChangeSummary: 7 // This code is inspired by ChangeSummary:
8 // https://github.com/rafaelw/ChangeSummary/blob/master/change_summary.js 8 // https://github.com/rafaelw/ChangeSummary/blob/master/change_summary.js
9 // ...which underlies MDV. Since we don't need the functionality of 9 // ...which underlies MDV. Since we don't need the functionality of
10 // ChangeSummary, we just implement what we need for data bindings. 10 // ChangeSummary, we just implement what we need for data bindings.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 * Observes [path] on [object] for changes. This returns an object that can be 65 * Observes [path] on [object] for changes. This returns an object that can be
66 * used to get the changes and get/set the value at this path. 66 * used to get the changes and get/set the value at this path.
67 * See [PathObserver.values] and [PathObserver.value]. 67 * See [PathObserver.values] and [PathObserver.value].
68 */ 68 */
69 PathObserver(this.object, String path) 69 PathObserver(this.object, String path)
70 : path = path, _isValid = _isPathValid(path) { 70 : path = path, _isValid = _isPathValid(path) {
71 71
72 // TODO(jmesserly): if the path is empty, or the object is! Observable, we 72 // TODO(jmesserly): if the path is empty, or the object is! Observable, we
73 // can optimize the PathObserver to be more lightweight. 73 // can optimize the PathObserver to be more lightweight.
74 74
75 _values = new StreamController.multiplex(onListen: _observe, 75 _values = new StreamController.broadcast(onListen: _observe,
76 onCancel: _unobserve); 76 onCancel: _unobserve);
77 77
78 if (_isValid) { 78 if (_isValid) {
79 var segments = []; 79 var segments = [];
80 for (var segment in path.trim().split('.')) { 80 for (var segment in path.trim().split('.')) {
81 if (segment == '') continue; 81 if (segment == '') continue;
82 var index = int.parse(segment, onError: (_) {}); 82 var index = int.parse(segment, onError: (_) {});
83 segments.add(index != null ? index : new Symbol(segment)); 83 segments.add(index != null ? index : new Symbol(segment));
84 } 84 }
85 85
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 final _spacesRegExp = new RegExp(r'\s'); 279 final _spacesRegExp = new RegExp(r'\s');
280 280
281 bool _isPathValid(String s) { 281 bool _isPathValid(String s) {
282 s = s.replaceAll(_spacesRegExp, ''); 282 s = s.replaceAll(_spacesRegExp, '');
283 283
284 if (s == '') return true; 284 if (s == '') return true;
285 if (s[0] == '.') return false; 285 if (s[0] == '.') return false;
286 return _pathRegExp.hasMatch(s); 286 return _pathRegExp.hasMatch(s);
287 } 287 }
OLDNEW
« sdk/lib/async/stream_controller.dart ('K') | « tests/lib/async/stream_controller_async_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698