@@ -637,11 +637,11 @@ _scanAdditionalContextDescriptors(TypeMetadataPrivateState &T) {
637
637
// Search for a ContextDescriptor in the context descriptor cache matching the
638
638
// given demangle node. Returns the found node, or nullptr if no match was
639
639
// found.
640
- static const ContextDescriptor *
640
+ static llvm::TinyPtrVector< const ContextDescriptor *>
641
641
_findContextDescriptorInCache (TypeMetadataPrivateState &T,
642
642
Demangle::NodePointer node) {
643
643
if (node->getNumChildren () < 2 )
644
- return nullptr ;
644
+ return { } ;
645
645
646
646
auto nameNode = node->getChild (1 );
647
647
@@ -651,21 +651,15 @@ _findContextDescriptorInCache(TypeMetadataPrivateState &T,
651
651
nameNode = nameNode->getChild (1 );
652
652
653
653
if (nameNode->getKind () != Demangle::Node::Kind::Identifier)
654
- return nullptr ;
654
+ return { } ;
655
655
656
656
auto name = nameNode->getText ();
657
657
658
658
auto iter = T.ContextDescriptorCache .find (name);
659
659
if (iter == T.ContextDescriptorCache .end ())
660
- return nullptr ;
661
-
662
- for (auto *contextDescriptor : iter->getSecond ()) {
663
- if (_contextDescriptorMatchesMangling (contextDescriptor, node)) {
664
- return contextDescriptor;
665
- }
666
- }
667
-
668
- return nullptr ;
660
+ return { };
661
+
662
+ return iter->getSecond ();
669
663
}
670
664
671
665
static const ContextDescriptor *
@@ -697,10 +691,18 @@ _findContextDescriptor(Demangle::NodePointer node,
697
691
698
692
// Scan any newly loaded images for context descriptors, then try the context
699
693
// descriptor cache. This must be done with the cache's lock held.
694
+ llvm::TinyPtrVector<const ContextDescriptor *> cachedContexts;
700
695
{
701
696
ScopedLock guard (T.ContextDescriptorCacheLock );
702
697
_scanAdditionalContextDescriptors (T);
703
- foundContext = _findContextDescriptorInCache (T, node);
698
+ cachedContexts = _findContextDescriptorInCache (T, node);
699
+ }
700
+
701
+ for (auto cachedContext : cachedContexts) {
702
+ if (_contextDescriptorMatchesMangling (cachedContext, node)) {
703
+ foundContext = cachedContext;
704
+ break ;
705
+ }
704
706
}
705
707
706
708
// Check type metadata records
0 commit comments