File tree Expand file tree Collapse file tree 5 files changed +40
-15
lines changed Expand file tree Collapse file tree 5 files changed +40
-15
lines changed Original file line number Diff line number Diff line change 4
4
5
5
// / Used for std::string conformance to Swift.Hashable
6
6
typedef std::hash<std::string> __swift_interopHashOfString;
7
- inline std::size_t __swift_interopComputeHashOfString (std::string str) {
7
+ inline std::size_t __swift_interopComputeHashOfString (const std::string & str) {
8
8
return __swift_interopHashOfString ()(str);
9
9
}
10
10
11
11
// / Used for std::u16string conformance to Swift.Hashable
12
12
typedef std::hash<std::u16string> __swift_interopHashOfU16String;
13
- inline std::size_t __swift_interopComputeHashOfU16String (std::u16string str) {
13
+ inline std::size_t __swift_interopComputeHashOfU16String (const std::u16string & str) {
14
14
return __swift_interopHashOfU16String ()(str);
15
15
}
16
16
17
17
// / Used for std::u32string conformance to Swift.Hashable
18
18
typedef std::hash<std::u32string> __swift_interopHashOfU32String;
19
- inline std::size_t __swift_interopComputeHashOfU32String (std::u32string str) {
19
+ inline std::size_t __swift_interopComputeHashOfU32String (const std::u32string & str) {
20
20
return __swift_interopHashOfU32String ()(str);
21
21
}
22
22
Original file line number Diff line number Diff line change @@ -198,11 +198,7 @@ extension std.string: Hashable {
198
198
@_alwaysEmitIntoClient
199
199
public func hash( into hasher: inout Hasher ) {
200
200
// Call std::hash<std::string>::operator()
201
- #if os(Windows) // FIXME: https://github.com/swiftlang/swift/issues/77856
202
- let cxxHash = __swift_interopHashOfString ( ) . callAsFunction ( self )
203
- #else
204
201
let cxxHash = __swift_interopComputeHashOfString ( self )
205
- #endif
206
202
hasher. combine ( cxxHash)
207
203
}
208
204
}
@@ -211,11 +207,7 @@ extension std.u16string: Hashable {
211
207
@_alwaysEmitIntoClient
212
208
public func hash( into hasher: inout Hasher ) {
213
209
// Call std::hash<std::u16string>::operator()
214
- #if os(Windows) // FIXME: https://github.com/swiftlang/swift/issues/77856
215
- let cxxHash = __swift_interopHashOfU16String ( ) . callAsFunction ( self )
216
- #else
217
210
let cxxHash = __swift_interopComputeHashOfU16String ( self )
218
- #endif
219
211
hasher. combine ( cxxHash)
220
212
}
221
213
}
@@ -224,11 +216,7 @@ extension std.u32string: Hashable {
224
216
@_alwaysEmitIntoClient
225
217
public func hash( into hasher: inout Hasher ) {
226
218
// Call std::hash<std::u32string>::operator()
227
- #if os(Windows) // FIXME: https://github.com/swiftlang/swift/issues/77856
228
- let cxxHash = __swift_interopHashOfU32String ( ) . callAsFunction ( self )
229
- #else
230
219
let cxxHash = __swift_interopComputeHashOfU32String ( self )
231
- #endif
232
220
hasher. combine ( cxxHash)
233
221
}
234
222
}
Original file line number Diff line number Diff line change @@ -40,6 +40,12 @@ module StdString {
40
40
export *
41
41
}
42
42
43
+ module StdStringAndVector {
44
+ header "std-string-and-vector.h"
45
+ requires cplusplus
46
+ export *
47
+ }
48
+
43
49
module StdStringView {
44
50
header "std-string-view.h"
45
51
requires cplusplus
Original file line number Diff line number Diff line change
1
+ #include < string>
2
+ #include < vector>
3
+
4
+ struct Item {
5
+ std::vector<std::string> keys;
6
+ std::vector<std::string> values;
7
+ };
8
+
9
+ inline Item get_item () {
10
+ return {};
11
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=default -Xcc -std=c++20 -O)
2
+ //
3
+ // REQUIRES: executable_test
4
+
5
+ // Tests optimizations related to CxxStdlib.
6
+
7
+ import StdlibUnittest
8
+ import CxxStdlib
9
+ import StdStringAndVector
10
+
11
+ var StdStringOptTestSuite = TestSuite ( " StdStringWithOpts " )
12
+
13
+ StdStringOptTestSuite . test ( " std::string with Hashable conformance optimized " ) {
14
+ let item = get_item ( )
15
+ let dict = Dictionary ( uniqueKeysWithValues: zip ( item. keys, item. values) . lazy)
16
+
17
+ expectEqual ( dict. count, 0 )
18
+ }
19
+
20
+ runAllTests ( )
You can’t perform that action at this time.
0 commit comments