@@ -25,7 +25,7 @@ using namespace swift::test;
2525namespace {
2626
2727class Registry {
28- DenseMap<StringRef, FunctionTest * > registeredTests;
28+ StringMap< FunctionTest> registeredTests;
2929 SwiftNativeFunctionTestThunk thunk;
3030
3131public:
@@ -34,7 +34,7 @@ class Registry {
3434 return registry;
3535 }
3636
37- void registerFunctionTest (FunctionTest * test, StringRef name) {
37+ void registerFunctionTest (FunctionTest test, StringRef name) {
3838 auto inserted = registeredTests.insert ({name, test}).second ;
3939 assert (inserted);
4040 (void )inserted;
@@ -46,20 +46,21 @@ class Registry {
4646
4747 SwiftNativeFunctionTestThunk getFunctionTestThunk () { return thunk; }
4848
49- FunctionTest * getFunctionTest (StringRef name) {
50- auto *res = registeredTests[ name] ;
51- if (!res ) {
49+ FunctionTest getFunctionTest (StringRef name) {
50+ auto iter = registeredTests. find ( name) ;
51+ if (iter == registeredTests. end () ) {
5252 llvm::errs () << " Found no test named " << name << " !\n " ;
5353 print (llvm::errs ());
5454 }
55- return res ;
55+ return iter-> getValue () ;
5656 }
5757
5858 void print (raw_ostream &OS) const {
5959 OS << " test::Registry(" << this << " ) with " << registeredTests.size ()
6060 << " entries: {{\n " ;
61- for (auto pair : registeredTests) {
62- OS << " \t " << pair.getFirst () << " -> " << pair.getSecond () << " \n " ;
61+ for (auto &stringMapEntry : registeredTests) {
62+ OS << " \t " << stringMapEntry.getKey () << " -> "
63+ << &stringMapEntry.getValue () << " \n " ;
6364 }
6465 OS << " }} test::Registry(" << this << " )\n " ;
6566 }
@@ -76,21 +77,18 @@ void registerFunctionTestThunk(SwiftNativeFunctionTestThunk thunk) {
7677FunctionTest::FunctionTest (StringRef name, Invocation invocation)
7778 : invocation(invocation), pass(nullptr ), function(nullptr ),
7879 dependencies(nullptr ) {
79- Registry::get ().registerFunctionTest (this , name);
80+ Registry::get ().registerFunctionTest (* this , name);
8081}
8182FunctionTest::FunctionTest (StringRef name, NativeSwiftInvocation invocation)
8283 : invocation(invocation), pass(nullptr ), function(nullptr ),
8384 dependencies(nullptr ) {}
8485
8586void FunctionTest::createNativeSwiftFunctionTest (
8687 StringRef name, NativeSwiftInvocation invocation) {
87- // / Statically allocate the tests to avoid triggering LSAN's "leak" detection.
88- static SmallVector<FunctionTest, 4 > tests;
89- auto &test = tests.emplace_back (name, invocation);
90- Registry::get ().registerFunctionTest (&test, name);
88+ Registry::get ().registerFunctionTest ({name, invocation}, name);
9189}
9290
93- FunctionTest * FunctionTest::get (StringRef name) {
91+ FunctionTest FunctionTest::get (StringRef name) {
9492 return Registry::get ().getFunctionTest (name);
9593}
9694
0 commit comments