File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,18 +26,14 @@ struct string_hash {
2626
2727struct string_eq {
2828 using is_transparent = void ;
29- // NOTE: The reason why std::string& comes first is because the key type of
30- // the map is std::string. (I couldn't figure out where this is specified,
31- // but looking at the implementation of std::unordered_map this seems to be
32- // the case.)
33- bool operator ()(const std::string& a, const std::string& b) const {
34- return a == b;
35- }
36- bool operator ()(const std::string& a, std::string_view b) const {
37- return a == b;
38- }
39- bool operator ()(const std::string& a, ObjString* b) const {
40- return a == b->value ;
29+
30+ static std::string_view to_view (const std::string& s) { return s; }
31+ static std::string_view to_view (std::string_view s) { return s; }
32+ static std::string_view to_view (ObjString* obj) { return obj->value ; }
33+
34+ template <typename T, typename U>
35+ bool operator ()(const T& t, const U& u) const {
36+ return to_view (t) == to_view (u);
4137 }
4238};
4339
Original file line number Diff line number Diff line change 1- fun bench() {
2- var result = 0;
3- for (var i = 0; i < 10000000; i = i + 1) {
4- result = result + 1;
5- }
6- return result;
1+ var result = 0;
2+ for (var i = 0; i < 10000000; i = i + 1) {
3+ result = result + 1;
74}
8- print bench() ;
5+ print result ;
You can’t perform that action at this time.
0 commit comments