@@ -25,7 +25,7 @@ using namespace swift::test;
25
25
namespace {
26
26
27
27
class Registry {
28
- StringMap<FunctionTest * > registeredTests;
28
+ StringMap<FunctionTest> registeredTests;
29
29
SwiftNativeFunctionTestThunk thunk;
30
30
31
31
public:
@@ -34,7 +34,7 @@ class Registry {
34
34
return registry;
35
35
}
36
36
37
- void registerFunctionTest (FunctionTest * test, StringRef name) {
37
+ void registerFunctionTest (FunctionTest test, StringRef name) {
38
38
auto inserted = registeredTests.insert ({name, test}).second ;
39
39
assert (inserted);
40
40
(void )inserted;
@@ -46,22 +46,21 @@ class Registry {
46
46
47
47
SwiftNativeFunctionTestThunk getFunctionTestThunk () { return thunk; }
48
48
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 ()) {
53
52
llvm::errs () << " Found no test named " << name << " !\n " ;
54
53
print (llvm::errs ());
55
54
}
56
- return res ;
55
+ return iter-> getValue () ;
57
56
}
58
57
59
58
void print (raw_ostream &OS) const {
60
59
OS << " test::Registry(" << this << " ) with " << registeredTests.size ()
61
60
<< " entries: {{\n " ;
62
61
for (auto &stringMapEntry : registeredTests) {
63
62
OS << " \t " << stringMapEntry.getKey () << " -> "
64
- << stringMapEntry.getValue () << " \n " ;
63
+ << & stringMapEntry.getValue () << " \n " ;
65
64
}
66
65
OS << " }} test::Registry(" << this << " )\n " ;
67
66
}
@@ -78,21 +77,18 @@ void registerFunctionTestThunk(SwiftNativeFunctionTestThunk thunk) {
78
77
FunctionTest::FunctionTest (StringRef name, Invocation invocation)
79
78
: invocation(invocation), pass(nullptr ), function(nullptr ),
80
79
dependencies(nullptr ) {
81
- Registry::get ().registerFunctionTest (this , name);
80
+ Registry::get ().registerFunctionTest (* this , name);
82
81
}
83
82
FunctionTest::FunctionTest (StringRef name, NativeSwiftInvocation invocation)
84
83
: invocation(invocation), pass(nullptr ), function(nullptr ),
85
84
dependencies(nullptr ) {}
86
85
87
86
void FunctionTest::createNativeSwiftFunctionTest (
88
87
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);
93
89
}
94
90
95
- FunctionTest * FunctionTest::get (StringRef name) {
91
+ FunctionTest FunctionTest::get (StringRef name) {
96
92
return Registry::get ().getFunctionTest (name);
97
93
}
98
94
0 commit comments