Skip to content

Commit 40938a0

Browse files
authored
Fix stack overflows on complex packages (#1383)
* fix stack overflows by not recomputing canonical libraries * dartfmt * changelog
1 parent afeea82 commit 40938a0

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* added a new `--footer-text` command-line option, to allow adding additional
44
text in the package name and copyright section of the footer
5+
* Reduced stack depth by not recomputing findCanonicalLibraryFor (#1381)
56

67
## 0.10.0
78

dartdoc.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager">
3+
<component name="NewModuleRootManager" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/bin" />
55
<content url="file://$MODULE_DIR$">
66
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
@@ -33,7 +33,7 @@
3333
<excludeFolder url="file://$MODULE_DIR$/tool/packages" />
3434
</content>
3535
<orderEntry type="sourceFolder" forTests="false" />
36-
<orderEntry type="library" name="Dart Packages" level="project" />
3736
<orderEntry type="library" name="Dart SDK" level="project" />
37+
<orderEntry type="library" name="Dart SDK" level="application" />
3838
</component>
3939
</module>

lib/src/html/html_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class HtmlGenerator extends Generator {
4646
static Future<HtmlGenerator> create(
4747
{HtmlGeneratorOptions options,
4848
List<String> headers,
49-
List<String> footers, List<String> footerTexts}) async {
49+
List<String> footers,
50+
List<String> footerTexts}) async {
5051
var templates = await Templates.create(
5152
headerPaths: headers,
5253
footerPaths: footers,

lib/src/model.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,16 +2796,25 @@ class Package implements Nameable, Documentable {
27962796
@override
27972797
String toString() => isSdk ? 'SDK' : 'Package $name';
27982798

2799+
final Map<Element, Library> _canonicalLibraryFor = new Map();
2800+
27992801
/// Tries to find a top level library that references this element.
28002802
Library findCanonicalLibraryFor(Element e) {
2803+
assert(allLibrariesAdded);
2804+
2805+
if (_canonicalLibraryFor.containsKey(e)) {
2806+
return _canonicalLibraryFor[e];
2807+
}
2808+
_canonicalLibraryFor[e] = null;
28012809
for (Library library in libraries) {
28022810
if (library.modelElementsMap.containsKey(e)) {
28032811
if (library.modelElementsMap[e].isCanonical) {
2804-
return library;
2812+
_canonicalLibraryFor[e] = library;
2813+
break;
28052814
}
28062815
}
28072816
}
2808-
return null;
2817+
return _canonicalLibraryFor[e];
28092818
}
28102819

28112820
/// Tries to find a canonical ModelElement for this element.

0 commit comments

Comments
 (0)