Skip to content

Commit e788217

Browse files
author
David Ungar
committed
Use array for the cache.
1 parent babbfe0 commit e788217

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ class ASTContext final {
943943
}
944944

945945
/// Logically, there is a separate cache for each SourceFile.
946-
llvm::SmallVectorImpl<Type> &getDefaultTypeRequestCache(SourceFile *);
946+
Type &getDefaultTypeRequestCache(SourceFile *, KnownProtocolKind);
947947

948948
private:
949949
friend Decl;

include/swift/AST/TypeCheckRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class DefaultTypeRequest
361361
static bool getPerformLocalLookup(KnownProtocolKind);
362362
TypeChecker &getTypeChecker() const;
363363
SourceFile *getSourceFile() const;
364-
llvm::SmallVectorImpl<Type> &getCache() const;
364+
Type &getCache() const;
365365
bool isDependencyMissing(Type result) const;
366366
};
367367

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
293293
/// Caches of default types for DefaultTypeRequest.
294294
/// Used to be instance variables in the TypeChecker.
295295
/// There is a logically separate cache for each SourceFile.
296-
llvm::DenseMap<SourceFile *, llvm::SmallVector<Type, NumKnownProtocols>>
296+
llvm::DenseMap<SourceFile *, std::array<Type, NumKnownProtocols>>
297297
DefaultTypeRequestCaches;
298298

299299
/// Structure that captures data that is segregated into different
@@ -5080,7 +5080,7 @@ LayoutConstraint LayoutConstraint::getLayoutConstraint(LayoutConstraintKind Kind
50805080
return LayoutConstraint(New);
50815081
}
50825082

5083-
llvm::SmallVectorImpl<Type> &
5084-
ASTContext::getDefaultTypeRequestCache(SourceFile *SF) {
5085-
return getImpl().DefaultTypeRequestCaches[SF];
5083+
Type &
5084+
ASTContext::getDefaultTypeRequestCache(SourceFile *SF, KnownProtocolKind kind) {
5085+
return getImpl().DefaultTypeRequestCaches[SF][size_t(kind)];
50865086
}

lib/AST/TypeCheckRequests.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,20 +456,19 @@ SourceFile *DefaultTypeRequest::getSourceFile() const {
456456
return getDeclContext()->getParentSourceFile();
457457
}
458458

459-
llvm::SmallVectorImpl<Type> &DefaultTypeRequest::getCache() const {
459+
Type &DefaultTypeRequest::getCache() const {
460460
return getDeclContext()->getASTContext().getDefaultTypeRequestCache(
461-
getSourceFile());
461+
getSourceFile(), getKnownProtocolKind());
462462
}
463463

464464
Optional<Type> DefaultTypeRequest::getCachedResult() const {
465-
auto const &cache = getCache();
466-
Type result = cache[size_t(getKnownProtocolKind())];
467-
if (!result)
465+
auto const &cachedType = getCache();
466+
if (!cachedType)
468467
return None;
469-
assert(!isDependencyMissing(result) &&
468+
assert(!isDependencyMissing(cachedType) &&
470469
"Since the cache is now cached by SourceFile, the dependency should "
471470
"have been recorded when it was looked up.");
472-
return result;
471+
return cachedType;
473472
}
474473

475474
bool DefaultTypeRequest::isDependencyMissing(Type result) const {
@@ -482,8 +481,7 @@ bool DefaultTypeRequest::isDependencyMissing(Type result) const {
482481
}
483482

484483
void DefaultTypeRequest::cacheResult(Type value) const {
485-
auto &cache = getCache();
486-
cache[size_t(getKnownProtocolKind())] = value;
484+
getCache() = value;
487485
}
488486

489487
const char *

0 commit comments

Comments
 (0)