Skip to content

Commit 62863bd

Browse files
committed
Use explicit keys for often accessed closures
1 parent 1358c8f commit 62863bd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/src/model.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,8 +1560,8 @@ abstract class GetterSetterCombo implements ModelElement {
15601560
if (targetClass.name == target.name) {
15611561
return original.replaceAll(constructorName, "${target.linkedName}");
15621562
}
1563-
return original.replaceAll(
1564-
"${targetClass.name}.${target.name}", "${targetClass.linkedName}.${target.linkedName}");
1563+
return original.replaceAll("${targetClass.name}.${target.name}",
1564+
"${targetClass.linkedName}.${target.linkedName}");
15651565
}
15661566

15671567
String _constantValueBase() {
@@ -2892,7 +2892,8 @@ abstract class ModelElement extends Canonicalization
28922892
///
28932893
/// For example: libraryName.className.methodName
28942894
@override
2895-
String get fullyQualifiedName => _memoizer.memoized(_buildFullyQualifiedName);
2895+
String get fullyQualifiedName => _memoizer.memoized(_buildFullyQualifiedName,
2896+
altKey: 'fullyQualifiedName');
28962897

28972898
String _fullyQualifiedNameWithoutLibrary() {
28982899
// Remember, periods are legal in library names.
@@ -2904,7 +2905,8 @@ abstract class ModelElement extends Canonicalization
29042905
// library.fullyQualifiedName seems somehow to break things.
29052906
//String get fullyQualifiedNameWithoutLibrary => _memoizer.memoized2(fullyQualifiedName.replaceFirst, "${library.fullyQualifiedName}.", '');
29062907
String get fullyQualifiedNameWithoutLibrary =>
2907-
_memoizer.memoized(_fullyQualifiedNameWithoutLibrary);
2908+
_memoizer.memoized(_fullyQualifiedNameWithoutLibrary,
2909+
altKey: 'fullyQualifiedNameWithoutLibrary');
29082910

29092911
String get sourceFileName => element.source.fullName;
29102912

lib/src/model_utils.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library dartdoc.model_utils;
77
import 'dart:collection';
88
import 'dart:convert';
99
import 'dart:io';
10+
import 'dart:mirrors';
1011

1112
import 'package:analyzer/dart/element/element.dart';
1213
import 'package:analyzer/src/generated/engine.dart';
@@ -266,8 +267,9 @@ class Memoizer {
266267

267268
/// Calls and caches the return value of [f]() if not in the cache, then
268269
/// returns the cached value of [f]().
269-
R memoized<R>(Function f) {
270-
_HashableList key = new _HashableList([f]);
270+
R memoized<R>(Function f, {String altKey}) {
271+
Object obj = altKey ?? f;
272+
_HashableList key = new _HashableList([obj]);
271273
return _cacheIfAbsent(key, f);
272274
}
273275

0 commit comments

Comments
 (0)