Skip to content

Commit 6bfba48

Browse files
authored
Revert "[swift-api-digester] caching the equality comparison results among SDKNodes. (#5297)" (#5391)
Practical measurement suggests the efficiency improvement is negligible, thus revert it.
1 parent 66d16f3 commit 6bfba48

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -808,45 +808,17 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
808808
return Result;
809809
}
810810

811-
/// This is for caching the comparison results between two SDKNodes.
812-
class SDKNodeEqualContext {
813-
using NodePtrAndEqual = llvm::DenseMap<const SDKNode*, bool>;
814-
llvm::DenseMap<const SDKNode*, llvm::DenseMap<const SDKNode*, bool>> Data;
815-
816-
public:
817-
Optional<bool> getEquality(const SDKNode* Left, const SDKNode* Right) {
818-
auto &Map = Data.insert({Left, NodePtrAndEqual()}).first->getSecond();
819-
if (Map.count(Right))
820-
return Map[Right];
821-
return None;
822-
}
823-
824-
void addEquality(const SDKNode* Left, const SDKNode* Right, const bool Value) {
825-
Data.insert(std::make_pair(Left, NodePtrAndEqual())).first->getSecond().
826-
insert({Right, Value});
827-
}
828-
};
829-
830811
bool SDKNode::operator==(const SDKNode &Other) const {
831-
static SDKNodeEqualContext EqualCache;
832-
if (auto Cached = EqualCache.getEquality(this, &Other)) {
833-
return Cached.getValue();
834-
}
835-
auto Exit = [&](const bool Result) {
836-
EqualCache.addEquality(this, &Other, Result);
837-
return Result;
838-
};
839-
840812
if (getKind() != Other.getKind())
841-
return Exit(false);
813+
return false;
842814

843815
switch(getKind()) {
844816
case SDKNodeKind::TypeNominal:
845817
case SDKNodeKind::TypeFunc: {
846818
auto Left = this->getAs<SDKNodeType>();
847819
auto Right = (&Other)->getAs<SDKNodeType>();
848-
return Exit(Left->getTypeAttributes().equals(Right->getTypeAttributes())
849-
&& Left->getPrintedName() == Right->getPrintedName());
820+
return Left->getTypeAttributes().equals(Right->getTypeAttributes())
821+
&& Left->getPrintedName() == Right->getPrintedName();
850822
}
851823

852824
case SDKNodeKind::Function:
@@ -856,9 +828,9 @@ bool SDKNode::operator==(const SDKNode &Other) const {
856828
auto Left = this->getAs<SDKNodeAbstractFunc>();
857829
auto Right = (&Other)->getAs<SDKNodeAbstractFunc>();
858830
if (Left->isMutating() ^ Right->isMutating())
859-
return Exit(false);
831+
return false;
860832
if (Left->isThrowing() ^ Right->isThrowing())
861-
return Exit(false);
833+
return false;
862834
SWIFT_FALLTHROUGH;
863835
}
864836
case SDKNodeKind::TypeDecl:
@@ -870,11 +842,11 @@ bool SDKNode::operator==(const SDKNode &Other) const {
870842
Children.size() == Other.Children.size()) {
871843
for (unsigned I = 0; I < Children.size(); ++ I) {
872844
if (*Children[I] != *Other.Children[I])
873-
return Exit(false);
845+
return false;
874846
}
875-
return Exit(true);
847+
return true;
876848
}
877-
return Exit(false);
849+
return false;
878850
}
879851
}
880852
}

0 commit comments

Comments
 (0)