@@ -25,7 +25,7 @@ using namespace swift::test;
25
25
namespace {
26
26
27
27
class Registry {
28
- DenseMap<StringRef, 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,20 +46,21 @@ class Registry {
46
46
47
47
SwiftNativeFunctionTestThunk getFunctionTestThunk () { return thunk; }
48
48
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 () ) {
52
52
llvm::errs () << " Found no test named " << name << " !\n " ;
53
53
print (llvm::errs ());
54
54
}
55
- return res ;
55
+ return iter-> getValue () ;
56
56
}
57
57
58
58
void print (raw_ostream &OS) const {
59
59
OS << " test::Registry(" << this << " ) with " << registeredTests.size ()
60
60
<< " 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 " ;
63
64
}
64
65
OS << " }} test::Registry(" << this << " )\n " ;
65
66
}
@@ -76,21 +77,18 @@ void registerFunctionTestThunk(SwiftNativeFunctionTestThunk thunk) {
76
77
FunctionTest::FunctionTest (StringRef name, Invocation invocation)
77
78
: invocation(invocation), pass(nullptr ), function(nullptr ),
78
79
dependencies(nullptr ) {
79
- Registry::get ().registerFunctionTest (this , name);
80
+ Registry::get ().registerFunctionTest (* this , name);
80
81
}
81
82
FunctionTest::FunctionTest (StringRef name, NativeSwiftInvocation invocation)
82
83
: invocation(invocation), pass(nullptr ), function(nullptr ),
83
84
dependencies(nullptr ) {}
84
85
85
86
void FunctionTest::createNativeSwiftFunctionTest (
86
87
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);
91
89
}
92
90
93
- FunctionTest * FunctionTest::get (StringRef name) {
91
+ FunctionTest FunctionTest::get (StringRef name) {
94
92
return Registry::get ().getFunctionTest (name);
95
93
}
96
94
0 commit comments