| OLD | NEW |
| 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 dump_info; | 5 library dump_info; |
| 6 | 6 |
| 7 import 'dart:convert' show | 7 import 'dart:convert' show |
| 8 HtmlEscape, | 8 HtmlEscape, |
| 9 JsonEncoder, | 9 JsonEncoder, |
| 10 StringConversionSink, | 10 StringConversionSink, |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 487 |
| 488 // Records the size of a dart AST node after it has been | 488 // Records the size of a dart AST node after it has been |
| 489 // pretty-printed into the output buffer. | 489 // pretty-printed into the output buffer. |
| 490 void recordAstSize(jsAst.Node node, int size) { | 490 void recordAstSize(jsAst.Node node, int size) { |
| 491 if (isTracking(node)) { | 491 if (isTracking(node)) { |
| 492 //TODO: should I be incrementing here instead? | 492 //TODO: should I be incrementing here instead? |
| 493 _nodeToSize[node] = size; | 493 _nodeToSize[node] = size; |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 // Field names are treated differently by the dart compiler | |
| 498 // so they must be recorded seperately. | |
| 499 void recordFieldNameSize(Element element, int size) { | |
| 500 _fieldNameToSize[element] = size; | |
| 501 } | |
| 502 | |
| 503 // Returns the size of the source code that | 497 // Returns the size of the source code that |
| 504 // was generated for an element. If no source | 498 // was generated for an element. If no source |
| 505 // code was produced, return 0. | 499 // code was produced, return 0. |
| 506 int sizeOf(Element element) { | 500 int sizeOf(Element element) { |
| 507 if (_fieldNameToSize.containsKey(element)) { | |
| 508 return _fieldNameToSize[element]; | |
| 509 } | |
| 510 if (_elementToNodes.containsKey(element)) { | 501 if (_elementToNodes.containsKey(element)) { |
| 511 return _elementToNodes[element] | 502 return _elementToNodes[element] |
| 512 .map(sizeOfNode) | 503 .map(sizeOfNode) |
| 513 .fold(0, (a, b) => a + b); | 504 .fold(0, (a, b) => a + b); |
| 514 } else { | 505 } else { |
| 515 return 0; | 506 return 0; |
| 516 } | 507 } |
| 517 } | 508 } |
| 518 | 509 |
| 519 int sizeOfNode(jsAst.Node node) { | 510 int sizeOfNode(jsAst.Node node) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 ChunkedConversionSink<Object> sink = | 633 ChunkedConversionSink<Object> sink = |
| 643 encoder.startChunkedConversion( | 634 encoder.startChunkedConversion( |
| 644 new StringConversionSink.fromStringSink(buffer)); | 635 new StringConversionSink.fromStringSink(buffer)); |
| 645 sink.add(outJson); | 636 sink.add(outJson); |
| 646 compiler.reportInfo(NO_LOCATION_SPANNABLE, | 637 compiler.reportInfo(NO_LOCATION_SPANNABLE, |
| 647 const MessageKind( | 638 const MessageKind( |
| 648 "View the dumped .info.json file at " | 639 "View the dumped .info.json file at " |
| 649 "https://dart-lang.github.io/dump-info-visualizer")); | 640 "https://dart-lang.github.io/dump-info-visualizer")); |
| 650 } | 641 } |
| 651 } | 642 } |
| OLD | NEW |