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 44
55// / Used for std::string conformance to Swift.Hashable
66typedef 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) {
88 return __swift_interopHashOfString ()(str);
99}
1010
1111// / Used for std::u16string conformance to Swift.Hashable
1212typedef 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) {
1414 return __swift_interopHashOfU16String ()(str);
1515}
1616
1717// / Used for std::u32string conformance to Swift.Hashable
1818typedef 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) {
2020 return __swift_interopHashOfU32String ()(str);
2121}
2222
Original file line number Diff line number Diff line change @@ -198,11 +198,7 @@ extension std.string: Hashable {
198198 @_alwaysEmitIntoClient
199199 public func hash( into hasher: inout Hasher ) {
200200 // 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
204201 let cxxHash = __swift_interopComputeHashOfString ( self )
205- #endif
206202 hasher. combine ( cxxHash)
207203 }
208204}
@@ -211,11 +207,7 @@ extension std.u16string: Hashable {
211207 @_alwaysEmitIntoClient
212208 public func hash( into hasher: inout Hasher ) {
213209 // 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
217210 let cxxHash = __swift_interopComputeHashOfU16String ( self )
218- #endif
219211 hasher. combine ( cxxHash)
220212 }
221213}
@@ -224,11 +216,7 @@ extension std.u32string: Hashable {
224216 @_alwaysEmitIntoClient
225217 public func hash( into hasher: inout Hasher ) {
226218 // 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
230219 let cxxHash = __swift_interopComputeHashOfU32String ( self )
231- #endif
232220 hasher. combine ( cxxHash)
233221 }
234222}
Original file line number Diff line number Diff line change @@ -40,6 +40,12 @@ module StdString {
4040 export *
4141}
4242
43+ module StdStringAndVector {
44+ header "std-string-and-vector.h"
45+ requires cplusplus
46+ export *
47+ }
48+
4349module StdStringView {
4450 header "std-string-view.h"
4551 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