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

Side by Side Diff: pkg/compiler/lib/src/io/source_map_builder.dart

Issue 2864573002: dart2js allocation tweaks (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
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 library dart2js.source_map_builder; 5 library dart2js.source_map_builder;
6 6
7 import 'package:kernel/ast.dart' show Location; 7 import 'package:kernel/ast.dart' show Location;
8 import '../../compiler_new.dart' show OutputSink, OutputType; 8 import '../../compiler_new.dart' show OutputSink, OutputType;
9 import '../util/uri_extras.dart' show relativize; 9 import '../util/uri_extras.dart' show relativize;
10 import '../util/util.dart'; 10 import '../util/util.dart';
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 class SourceMapEntry { 270 class SourceMapEntry {
271 SourceLocation sourceLocation; 271 SourceLocation sourceLocation;
272 int targetOffset; 272 int targetOffset;
273 273
274 SourceMapEntry(this.sourceLocation, this.targetOffset); 274 SourceMapEntry(this.sourceLocation, this.targetOffset);
275 } 275 }
276 276
277 /// Map from line/column pairs to lists of [T] elements. 277 /// Map from line/column pairs to lists of [T] elements.
278 class LineColumnMap<T> { 278 class LineColumnMap<T> {
279 Map<int, Map<int, List<T>>> _map = <int, Map<int, List<T>>>{}; 279 Map<int, Map<int, List<T>>> _map = <int, Map<int, List<T>>>{};
280 var _makeLineMap = () => <int, List<T>>{};
281 var _makeList = () => <T>[];
280 282
281 /// Returns the list of elements associated with ([line],[column]). 283 /// Returns the list of elements associated with ([line],[column]).
282 List<T> _getList(int line, int column) { 284 List<T> _getList(int line, int column) {
283 Map<int, List<T>> lineMap = _map.putIfAbsent(line, () => <int, List<T>>{}); 285 Map<int, List<T>> lineMap = _map.putIfAbsent(line, _makeLineMap);
284 return lineMap.putIfAbsent(column, () => <T>[]); 286 return lineMap.putIfAbsent(column, _makeList);
285 } 287 }
286 288
287 /// Adds [element] to the end of the list of elements associated with 289 /// Adds [element] to the end of the list of elements associated with
288 /// ([line],[column]). 290 /// ([line],[column]).
289 void add(int line, int column, T element) { 291 void add(int line, int column, T element) {
290 _getList(line, column).add(element); 292 _getList(line, column).add(element);
291 } 293 }
292 294
293 /// Adds [element] to the beginning of the list of elements associated with 295 /// Adds [element] to the beginning of the list of elements associated with
294 /// ([line],[column]). 296 /// ([line],[column]).
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 int register(T element) { 358 int register(T element) {
357 return map.putIfAbsent(element, () => map.length); 359 return map.putIfAbsent(element, () => map.length);
358 } 360 }
359 361
360 /// Returns the index of [element]. 362 /// Returns the index of [element].
361 int operator [](T element) => map[element]; 363 int operator [](T element) => map[element];
362 364
363 /// Returns the indexed elements. 365 /// Returns the indexed elements.
364 Iterable<T> get elements => map.keys; 366 Iterable<T> get elements => map.keys;
365 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698