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

Side by Side Diff: samples/chat/chat_server_lib.dart

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 7 years, 9 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 library chat_server; 5 library chat_server;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:math'; 10 import 'dart:math';
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 // range is split over a number of buckets where each bucket collects 618 // range is split over a number of buckets where each bucket collects
619 // the number of events happening in that time sub-range. The first 619 // the number of events happening in that time sub-range. The first
620 // constructor arument specifies the time range in milliseconds. The 620 // constructor arument specifies the time range in milliseconds. The
621 // buckets are in the list _buckets organized at a circular buffer 621 // buckets are in the list _buckets organized at a circular buffer
622 // with _currentBucket marking the bucket where an event was last 622 // with _currentBucket marking the bucket where an event was last
623 // recorded. A current sum of the content of all buckets except the 623 // recorded. A current sum of the content of all buckets except the
624 // one pointed a by _currentBucket is kept in _sum. 624 // one pointed a by _currentBucket is kept in _sum.
625 class Rate { 625 class Rate {
626 Rate([int timeRange = 1000, int buckets = 10]) 626 Rate([int timeRange = 1000, int buckets = 10])
627 : _timeRange = timeRange, 627 : _timeRange = timeRange,
628 _buckets = new List.fixedLength(buckets + 1), // Current bucket is not in the sum. 628 _buckets = new List(buckets + 1), // Current bucket is not in the sum.
629 _currentBucket = 0, 629 _currentBucket = 0,
630 _currentBucketTime = new DateTime.now().millisecondsSinceEpoch, 630 _currentBucketTime = new DateTime.now().millisecondsSinceEpoch,
631 _sum = 0 { 631 _sum = 0 {
632 _bucketTimeRange = (_timeRange / buckets).toInt(); 632 _bucketTimeRange = (_timeRange / buckets).toInt();
633 for (int i = 0; i < _buckets.length; i++) { 633 for (int i = 0; i < _buckets.length; i++) {
634 _buckets[i] = 0; 634 _buckets[i] = 0;
635 } 635 }
636 } 636 }
637 637
638 // Record the specified number of events. 638 // Record the specified number of events.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 671 }
672 } 672 }
673 673
674 int _timeRange; 674 int _timeRange;
675 List<int> _buckets; 675 List<int> _buckets;
676 int _currentBucket; 676 int _currentBucket;
677 int _currentBucketTime; 677 int _currentBucketTime;
678 num _bucketTimeRange; 678 num _bucketTimeRange;
679 int _sum; 679 int _sum;
680 } 680 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698