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

Unified Diff: sdk/lib/_internal/compiler/implementation/helpers/track_map.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/helpers/track_map.dart
diff --git a/sdk/lib/_internal/compiler/implementation/helpers/track_map.dart b/sdk/lib/_internal/compiler/implementation/helpers/track_map.dart
deleted file mode 100644
index 5f827a6cb5e70cc815a005bf6ce1a8bad1387c3d..0000000000000000000000000000000000000000
--- a/sdk/lib/_internal/compiler/implementation/helpers/track_map.dart
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-part of dart2js.helpers;
-
-/**
- * The track map is a simple wrapper around a map that keeps track
- * of the 'final' size of maps grouped by description. It allows
- * determining the distribution of sizes for a specific allocation
- * site and it can be used like this:
- *
- * Map<String, int> map = new TrackMap<String, int>("my-map");
- *
- * After finishing the compilaton, the histogram of track map sizes
- * is printed but only when running in verbose mode.
- */
-class TrackMap<K, V> implements Map<K, V> {
- final Map _map;
- final List _counts;
- static final Map<String, List<int>> _countsMap = {};
-
- TrackMap._internal(this._counts) : _map = new Map<K, V>();
-
- factory TrackMap(String description) {
- List counts = _countsMap.putIfAbsent(description, () => [ 0 ]);
- Map result = new TrackMap<K, V>._internal(counts);
- counts[0]++;
- return result;
- }
-
- static void printHistogram() {
- _countsMap.forEach((description, counts) {
- print('$description -- ${counts.length} maps');
-
- // Count the total number of maps.
- int sum = 0;
- for (int i = 0; i < counts.length; i++) {
- sum += counts[i];
- }
- int increment = sum ~/ 10;
- int target = increment;
- int accumulated = 0;
- for (int i = 0; i < counts.length; i++) {
- accumulated += counts[i];
- if (accumulated >= target) {
- String percent = (accumulated / sum * 100).toStringAsFixed(1);
- print(' -- $percent%: length <= $i');
- target += increment;
- }
- }
- });
- }
-
- int get length => _map.length;
- bool get isEmpty => _map.isEmpty;
- bool get isNotEmpty => _map.isNotEmpty;
-
- Iterable<K> get keys => _map.keys;
- Iterable<V> get values => _map.values;
-
- bool containsKey(K key) => _map.containsKey(key);
- bool containsValue(V value) => _map.containsValue(value);
-
- V operator[](K key) => _map[key];
- String toString() => _map.toString();
-
- void forEach(void action(K key, V value)) {
- _map.forEach(action);
- }
-
- void operator[]=(K key, V value) {
- if (!_map.containsKey(key)) {
- _notifyLengthChanged(1);
- _map[key] = value;
- }
- }
-
- V putIfAbsent(K key, V ifAbsent()) {
- if (containsKey(key)) return this[key];
- V value = ifAbsent();
- this[key] = value;
- return value;
- }
-
- V remove(Object key) {
- if (_map.containsKey(key)) {
- _notifyLengthChanged(-1);
- }
- return _map.remove(key);
- }
-
- void addAll(Map<K, V> other) {
- other.forEach((key, value) => this[key] = value);
- }
-
- void clear() {
- _notifyLengthChanged(-_map.length);
- _map.clear();
- }
-
- void _notifyLengthChanged(int delta) {
- int oldLength = _map.length;
- int newLength = oldLength + delta;
- _counts[oldLength]--;
- if (newLength < _counts.length) {
- _counts[newLength]++;
- } else {
- _counts.add(1);
- assert(newLength == _counts.length - 1);
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698