5
5
// DO NOT EDIT. This file was generated from async_import_cache.dart.
6
6
// See tool/grind/synchronize.dart for details.
7
7
//
8
- // Checksum: 36bc42050cf2eb3a43f36376c4f06c1708eee777
8
+ // Checksum: 4362e28e5cd425786c235d2a6a2bb60539403799
9
9
//
10
10
// ignore_for_file: unused_import
11
11
@@ -23,6 +23,7 @@ import 'importer/no_op.dart';
23
23
import 'importer/utils.dart' ;
24
24
import 'io.dart' ;
25
25
import 'logger.dart' ;
26
+ import 'util/map.dart' ;
26
27
import 'util/nullable.dart' ;
27
28
import 'utils.dart' ;
28
29
@@ -47,29 +48,26 @@ final class ImportCache {
47
48
/// The `forImport` in each key is true when this canonicalization is for an
48
49
/// `@import` rule. Otherwise, it's for a `@use` or `@forward` rule.
49
50
///
50
- /// This cache isn't used for relative imports, because they depend on the
51
- /// specific base importer. That's stored separately in
52
- /// [_relativeCanonicalizeCache ] .
51
+ /// This cache covers loads that go through the entire chain of [_importers] ,
52
+ /// but it doesn't cover individual loads or loads in which any importer
53
+ /// accesses `containingUrl` . See also [_perImporterCanonicalizeCache ] .
53
54
final _canonicalizeCache = < (Uri , {bool forImport}), CanonicalizeResult ? > {};
54
55
55
- /// The canonicalized URLs for each non-canonical URL that's resolved using a
56
- /// relative importer .
56
+ /// Like [_canonicalizeCache] but also includes the specific importer in the
57
+ /// key .
57
58
///
58
- /// The map's keys have four parts:
59
+ /// This is used to cache both relative imports from the base importer and
60
+ /// individual importer results in the case where some other component of the
61
+ /// importer chain isn't cacheable.
62
+ final _perImporterCanonicalizeCache =
63
+ < (Importer , Uri , {bool forImport}), CanonicalizeResult ? > {};
64
+
65
+ /// A map from the keys in [_perImporterCanonicalizeCache] that are generated
66
+ /// for relative URL loads agains the base importer to the original relative
67
+ /// URLs what were loaded.
59
68
///
60
- /// 1. The URL passed to [canonicalize] (the same as in [_canonicalizeCache] ).
61
- /// 2. Whether the canonicalization is for an `@import` rule.
62
- /// 3. The `baseImporter` passed to [canonicalize] .
63
- /// 4. The `baseUrl` passed to [canonicalize] .
64
- ///
65
- /// The map's values are the same as the return value of [canonicalize] .
66
- final _relativeCanonicalizeCache = < (
67
- Uri , {
68
- bool forImport,
69
- Importer baseImporter,
70
- Uri ? baseUrl
71
- }),
72
- CanonicalizeResult ? > {};
69
+ /// This is used to invalidate the cache when files are changed.
70
+ final _nonCanonicalRelativeUrls = < (Importer , Uri , {bool forImport}), Uri > {};
73
71
74
72
/// The parsed stylesheets for each canonicalized import URL.
75
73
final _importCache = < Uri , Stylesheet ? > {};
@@ -155,18 +153,16 @@ final class ImportCache {
155
153
}
156
154
157
155
if (baseImporter != null && url.scheme == '' ) {
158
- var relativeResult = _relativeCanonicalizeCache.putIfAbsent ((
159
- url,
160
- forImport: forImport,
161
- baseImporter: baseImporter,
162
- baseUrl: baseUrl
163
- ), () {
164
- var (result, cacheable) = _canonicalize (
165
- baseImporter, baseUrl? .resolveUri (url) ?? url, baseUrl, forImport);
156
+ var resolvedUrl = baseUrl? .resolveUri (url) ?? url;
157
+ var key = (baseImporter, resolvedUrl, forImport: forImport);
158
+ var relativeResult = _perImporterCanonicalizeCache.putIfAbsent (key, () {
159
+ var (result, cacheable) =
160
+ _canonicalize (baseImporter, resolvedUrl, baseUrl, forImport);
166
161
assert (
167
162
cacheable,
168
163
"Relative loads should always be cacheable because they never "
169
164
"provide access to the containing URL." );
165
+ if (baseUrl != null ) _nonCanonicalRelativeUrls[key] = url;
170
166
return result;
171
167
});
172
168
if (relativeResult != null ) return relativeResult;
@@ -182,17 +178,41 @@ final class ImportCache {
182
178
// `canonicalize()` calls we've attempted are cacheable. Only if they are do
183
179
// we store the result in the cache.
184
180
var cacheable = true ;
185
- for (var importer in _importers) {
181
+ for (var i = 0 ; i < _importers.length; i++ ) {
182
+ var importer = _importers[i];
183
+ var perImporterKey = (importer, url, forImport: forImport);
184
+ switch (_perImporterCanonicalizeCache.getOption (perImporterKey)) {
185
+ case (var result? ,):
186
+ return result;
187
+ case (null ,):
188
+ continue ;
189
+ }
190
+
186
191
switch (_canonicalize (importer, url, baseUrl, forImport)) {
187
192
case (var result? , true ) when cacheable:
188
193
_canonicalizeCache[key] = result;
189
194
return result;
190
195
191
- case (var result? , _):
192
- return result;
193
-
194
- case (_, false ):
195
- cacheable = false ;
196
+ case (var result, true ) when ! cacheable:
197
+ _perImporterCanonicalizeCache[perImporterKey] = result;
198
+ if (result != null ) return result;
199
+
200
+ case (var result, false ):
201
+ if (cacheable) {
202
+ // If this is the first uncacheable result, add all previous results
203
+ // to the per-importer cache so we don't have to re-run them for
204
+ // future uses of this importer.
205
+ for (var j = 0 ; j < i; j++ ) {
206
+ _perImporterCanonicalizeCache[(
207
+ _importers[j],
208
+ url,
209
+ forImport: forImport
210
+ )] = null ;
211
+ }
212
+ cacheable = false ;
213
+ }
214
+
215
+ if (result != null ) return result;
196
216
}
197
217
}
198
218
@@ -312,7 +332,7 @@ final class ImportCache {
312
332
Uri sourceMapUrl (Uri canonicalUrl) =>
313
333
_resultsCache[canonicalUrl]? .sourceMapUrl ?? canonicalUrl;
314
334
315
- /// Clears the cached canonical version of the given [url] .
335
+ /// Clears the cached canonical version of the given non-canonical [url] .
316
336
///
317
337
/// Has no effect if the canonical version of [url] has not been cached.
318
338
///
@@ -321,7 +341,8 @@ final class ImportCache {
321
341
void clearCanonicalize (Uri url) {
322
342
_canonicalizeCache.remove ((url, forImport: false ));
323
343
_canonicalizeCache.remove ((url, forImport: true ));
324
- _relativeCanonicalizeCache.removeWhere ((key, _) => key.$1 == url);
344
+ _perImporterCanonicalizeCache.removeWhere (
345
+ (key, _) => key.$2 == url || _nonCanonicalRelativeUrls[key] == url);
325
346
}
326
347
327
348
/// Clears the cached parse tree for the stylesheet with the given
0 commit comments