@@ -25,7 +25,7 @@ using namespace swift::test;
2525namespace {
2626
2727class Registry {
28- StringMap<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,22 +46,21 @@ class Registry {
4646
4747 SwiftNativeFunctionTestThunk getFunctionTestThunk () { return thunk; }
4848
49- FunctionTest *getFunctionTest (StringRef name) {
50- // Avoid creating a new entry here.
51- auto *res = registeredTests.lookup (name);
52- if (!res) {
49+ FunctionTest getFunctionTest (StringRef name) {
50+ auto iter = registeredTests.find (name);
51+ if (iter == registeredTests.end ()) {
5352 llvm::errs () << " Found no test named " << name << " !\n " ;
5453 print (llvm::errs ());
5554 }
56- return res ;
55+ return iter-> getValue () ;
5756 }
5857
5958 void print (raw_ostream &OS) const {
6059 OS << " test::Registry(" << this << " ) with " << registeredTests.size ()
6160 << " entries: {{\n " ;
6261 for (auto &stringMapEntry : registeredTests) {
6362 OS << " \t " << stringMapEntry.getKey () << " -> "
64- << stringMapEntry.getValue () << " \n " ;
63+ << & stringMapEntry.getValue () << " \n " ;
6564 }
6665 OS << " }} test::Registry(" << this << " )\n " ;
6766 }
@@ -78,21 +77,18 @@ void registerFunctionTestThunk(SwiftNativeFunctionTestThunk thunk) {
7877FunctionTest::FunctionTest (StringRef name, Invocation invocation)
7978 : invocation(invocation), pass(nullptr ), function(nullptr ),
8079 dependencies(nullptr ) {
81- Registry::get ().registerFunctionTest (this , name);
80+ Registry::get ().registerFunctionTest (* this , name);
8281}
8382FunctionTest::FunctionTest (StringRef name, NativeSwiftInvocation invocation)
8483 : invocation(invocation), pass(nullptr ), function(nullptr ),
8584 dependencies(nullptr ) {}
8685
8786void FunctionTest::createNativeSwiftFunctionTest (
8887 StringRef name, NativeSwiftInvocation invocation) {
89- // / Statically allocate the tests to avoid triggering LSAN's "leak" detection.
90- static SmallVector<FunctionTest, 4 > tests;
91- auto &test = tests.emplace_back (name, invocation);
92- Registry::get ().registerFunctionTest (&test, name);
88+ Registry::get ().registerFunctionTest ({name, invocation}, name);
9389}
9490
95- FunctionTest * FunctionTest::get (StringRef name) {
91+ FunctionTest FunctionTest::get (StringRef name) {
9692 return Registry::get ().getFunctionTest (name);
9793}
9894
0 commit comments