|
159 | 159 | #include "swift/AST/TypeRepr.h"
|
160 | 160 | #include "llvm/ADT/SmallVector.h"
|
161 | 161 | #include "llvm/ADT/SetVector.h"
|
162 |
| -#include "swift/Basic/Defer.h" |
163 | 162 | #include "Diagnostics.h"
|
164 | 163 | #include "RewriteContext.h"
|
165 | 164 | #include "NameLookup.h"
|
@@ -779,6 +778,19 @@ void swift::rewriting::expandDefaultRequirements(ASTContext &ctx,
|
779 | 778 | if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics))
|
780 | 779 | return;
|
781 | 780 |
|
| 781 | + // TODO(kavon): we can be more efficient in two ways: |
| 782 | + // 1. Instead of allocating space in this map for each target to describe |
| 783 | + // defaults, which are much more common, we use the set to track inverses |
| 784 | + // only so that the more common case has no overhead beyond just adding |
| 785 | + // the defaults. This should yield a constant-time improvement. |
| 786 | + // |
| 787 | + // 2. Instead of searching the _entire_ results vector for inverses, we can |
| 788 | + // take advantage of the fact that the requirements appended by nesting |
| 789 | + // level. Thus, we could get an iterator position for the start of the |
| 790 | + // removal search, which would be the end of the `result` vector before |
| 791 | + // requirements for the current subjects got pushed there. This should |
| 792 | + // yield a O(|result|^2) -> O(|result|) performance improvement. |
| 793 | + |
782 | 794 | llvm::DenseMap<CanType, InvertibleProtocolSet> defaults;
|
783 | 795 | for (auto subject : subjects)
|
784 | 796 | defaults.insert({ subject->getCanonicalType(),
|
@@ -811,8 +823,6 @@ void swift::rewriting::expandDefaultRequirements(ASTContext &ctx,
|
811 | 823 | return true;
|
812 | 824 | }
|
813 | 825 |
|
814 |
| - // TODO: check for redundant inverses. |
815 |
| - |
816 | 826 | // Apply the inverse to the subject's defaults.
|
817 | 827 | defaults[subject].remove(inverse->getInverseKind());
|
818 | 828 |
|
|
0 commit comments