@@ -18,43 +18,34 @@ struct SwiftMangledName {
18
18
19
19
std::string str () const ;
20
20
21
- // streaming labels or ints into a SwiftMangledName just appends them
22
- template <typename Tag>
23
- SwiftMangledName& operator <<(TrapLabel<Tag> label) {
24
- assert (label && " using undefined label in mangled name" );
25
- parts.emplace_back (label);
26
- return *this ;
27
- }
21
+ // let's avoid copying as long as we don't need it
22
+ SwiftMangledName () = default ;
23
+ SwiftMangledName (const SwiftMangledName&) = delete ;
24
+ SwiftMangledName& operator =(const SwiftMangledName&) = delete ;
25
+ SwiftMangledName (SwiftMangledName&&) = default ;
26
+ SwiftMangledName& operator =(SwiftMangledName&&) = default ;
28
27
29
- SwiftMangledName& operator <<(unsigned i) {
30
- parts.emplace_back (i);
31
- return *this ;
32
- }
28
+ // streaming labels or ints into a SwiftMangledName just appends them
29
+ SwiftMangledName& operator <<(UntypedTrapLabel label) &;
30
+ SwiftMangledName& operator <<(unsigned i) &;
33
31
34
32
// streaming string-like stuff will add a new part it only if strictly required, otherwise it will
35
33
// append to the last part if it is a string
36
34
template <typename T>
37
- SwiftMangledName& operator <<(T&& arg) {
35
+ SwiftMangledName& operator <<(T&& arg) & {
38
36
if (parts.empty () || !std::holds_alternative<std::string>(parts.back ())) {
39
37
parts.emplace_back (" " );
40
38
}
41
39
std::get<std::string>(parts.back ()) += std::forward<T>(arg);
42
40
return *this ;
43
41
}
44
42
45
- SwiftMangledName& operator <<(SwiftMangledName&& other) {
46
- parts.reserve (parts.size () + other.parts .size ());
47
- for (auto & p : other.parts ) {
48
- parts.emplace_back (std::move (p));
49
- }
50
- other.parts .clear ();
51
- return *this ;
52
- }
43
+ SwiftMangledName& operator <<(SwiftMangledName&& other) &;
44
+ SwiftMangledName& operator <<(const SwiftMangledName& other) &;
53
45
54
- SwiftMangledName& operator <<(const SwiftMangledName& other) {
55
- parts.reserve (parts.size () + other.parts .size ());
56
- parts.insert (parts.end (), other.parts .begin (), other.parts .end ());
57
- return *this ;
46
+ template <typename T>
47
+ SwiftMangledName&& operator <<(T&& arg) && {
48
+ return std::move (operator <<(std::forward<T>(arg)));
58
49
}
59
50
};
60
51
0 commit comments