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

Side by Side Diff: pkg/barback/lib/src/utils.dart

Issue 68103027: Serialize binary barback assets using typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « pkg/barback/lib/src/internal_asset.dart ('k') | pkg/http/lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library barback.utils; 5 library barback.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:typed_data';
8 9
9 /// A pair of values. 10 /// A pair of values.
10 class Pair<E, F> { 11 class Pair<E, F> {
11 E first; 12 E first;
12 F last; 13 F last;
13 14
14 Pair(this.first, this.last); 15 Pair(this.first, this.last);
15 16
16 String toString() => '($first, $last)'; 17 String toString() => '($first, $last)';
17 18
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 /// Converts a number in the range [0-255] to a two digit hex string. 73 /// Converts a number in the range [0-255] to a two digit hex string.
73 /// 74 ///
74 /// For example, given `255`, returns `ff`. 75 /// For example, given `255`, returns `ff`.
75 String byteToHex(int byte) { 76 String byteToHex(int byte) {
76 assert(byte >= 0 && byte <= 255); 77 assert(byte >= 0 && byte <= 255);
77 78
78 const DIGITS = "0123456789abcdef"; 79 const DIGITS = "0123456789abcdef";
79 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16]; 80 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16];
80 } 81 }
81 82
83 /// Converts [input] into a [Uint8List].
84 ///
85 /// If [input] is a [TypedData], this just returns a view on [input].
86 Uint8List toUint8List(List<int> input) {
87 if (input is Uint8List) return input;
88 if (input is TypedData) return new Uint8List.view(input.buffer);
89 return new Uint8List.fromList(input);
90 }
91
82 /// Group the elements in [iter] by the value returned by [fn]. 92 /// Group the elements in [iter] by the value returned by [fn].
83 /// 93 ///
84 /// This returns a map whose keys are the return values of [fn] and whose values 94 /// This returns a map whose keys are the return values of [fn] and whose values
85 /// are lists of each element in [iter] for which [fn] returned that key. 95 /// are lists of each element in [iter] for which [fn] returned that key.
86 Map<Object, List> groupBy(Iterable iter, fn(element)) { 96 Map<Object, List> groupBy(Iterable iter, fn(element)) {
87 var map = {}; 97 var map = {};
88 for (var element in iter) { 98 for (var element in iter) {
89 var list = map.putIfAbsent(fn(element), () => []); 99 var list = map.putIfAbsent(fn(element), () => []);
90 list.add(element); 100 list.add(element);
91 } 101 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 subscription = callback().listen(controller.add, 248 subscription = callback().listen(controller.add,
239 onError: controller.addError, 249 onError: controller.addError,
240 onDone: controller.close); 250 onDone: controller.close);
241 }, 251 },
242 onCancel: () => subscription.cancel(), 252 onCancel: () => subscription.cancel(),
243 onPause: () => subscription.pause(), 253 onPause: () => subscription.pause(),
244 onResume: () => subscription.resume(), 254 onResume: () => subscription.resume(),
245 sync: true); 255 sync: true);
246 return controller.stream; 256 return controller.stream;
247 } 257 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/internal_asset.dart ('k') | pkg/http/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698