diff --git a/net/dcsctp/common/BUILD.gn b/net/dcsctp/common/BUILD.gn index 6e99cdcef4..591fa44207 100644 --- a/net/dcsctp/common/BUILD.gn +++ b/net/dcsctp/common/BUILD.gn @@ -21,11 +21,6 @@ rtc_source_set("math") { sources = [ "math.h" ] } -rtc_source_set("pair_hash") { - deps = [] - sources = [ "pair_hash.h" ] -} - rtc_source_set("sequence_numbers") { deps = [ ":internal_types" ] sources = [ "sequence_numbers.h" ] @@ -44,7 +39,6 @@ if (rtc_include_tests) { defines = [] deps = [ ":math", - ":pair_hash", ":sequence_numbers", ":str_join", "../../../api:array_view", @@ -55,7 +49,6 @@ if (rtc_include_tests) { ] sources = [ "math_test.cc", - "pair_hash_test.cc", "sequence_numbers_test.cc", "str_join_test.cc", ] diff --git a/net/dcsctp/common/internal_types.h b/net/dcsctp/common/internal_types.h index b651d45d91..3bbc05e445 100644 --- a/net/dcsctp/common/internal_types.h +++ b/net/dcsctp/common/internal_types.h @@ -38,13 +38,5 @@ using VerificationTag = StrongAlias; // Tie Tag, used as a nonce when connecting. using TieTag = StrongAlias; -// Hasher for separated ordered/unordered stream identifiers. -struct UnorderedStreamHash { - size_t operator()(const std::pair& p) const { - return std::hash{}(*p.first) ^ - (std::hash{}(*p.second) << 1); - } -}; - } // namespace dcsctp #endif // NET_DCSCTP_COMMON_INTERNAL_TYPES_H_ diff --git a/net/dcsctp/common/pair_hash.h b/net/dcsctp/common/pair_hash.h deleted file mode 100644 index 62af8b4221..0000000000 --- a/net/dcsctp/common/pair_hash.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ -#ifndef NET_DCSCTP_COMMON_PAIR_HASH_H_ -#define NET_DCSCTP_COMMON_PAIR_HASH_H_ - -#include - -#include -#include - -namespace dcsctp { - -// A custom hash function for std::pair, to be able to be used as key in a -// std::unordered_map. If absl::flat_hash_map would ever be used, this is -// unnecessary as it already has a hash function for std::pair. -struct PairHash { - template - size_t operator()(const std::pair& p) const { - return (3 * std::hash{}(p.first)) ^ std::hash{}(p.second); - } -}; -} // namespace dcsctp - -#endif // NET_DCSCTP_COMMON_PAIR_HASH_H_ diff --git a/net/dcsctp/common/pair_hash_test.cc b/net/dcsctp/common/pair_hash_test.cc deleted file mode 100644 index bcc3ec86c0..0000000000 --- a/net/dcsctp/common/pair_hash_test.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ -#include "net/dcsctp/common/pair_hash.h" - -#include -#include - -#include "test/gmock.h" - -namespace dcsctp { -namespace { - -TEST(PairHashTest, CanInsertIntoSet) { - using MyPair = std::pair; - - std::unordered_set pairs; - - pairs.insert({1, 2}); - pairs.insert({3, 4}); - - EXPECT_NE(pairs.find({1, 2}), pairs.end()); - EXPECT_NE(pairs.find({3, 4}), pairs.end()); - EXPECT_EQ(pairs.find({1, 3}), pairs.end()); - EXPECT_EQ(pairs.find({3, 3}), pairs.end()); -} - -TEST(PairHashTest, CanInsertIntoMap) { - using MyPair = std::pair; - - std::unordered_map pairs; - - pairs[{1, 2}] = 99; - pairs[{3, 4}] = 100; - - EXPECT_EQ((pairs[{1, 2}]), 99); - EXPECT_EQ((pairs[{3, 4}]), 100); - EXPECT_EQ(pairs.find({1, 3}), pairs.end()); - EXPECT_EQ(pairs.find({3, 3}), pairs.end()); -} -} // namespace -} // namespace dcsctp diff --git a/net/dcsctp/public/BUILD.gn b/net/dcsctp/public/BUILD.gn index ced94de151..d92207be48 100644 --- a/net/dcsctp/public/BUILD.gn +++ b/net/dcsctp/public/BUILD.gn @@ -92,6 +92,7 @@ if (rtc_include_tests) { "../../../rtc_base:checks", "../../../rtc_base:gunit_helpers", "../../../rtc_base:rtc_base_approved", + "../../../rtc_base/containers:flat_map", "../../../test:test_support", ] sources = [ diff --git a/net/dcsctp/public/strong_alias.h b/net/dcsctp/public/strong_alias.h index 7aea362c57..fd6302d2ed 100644 --- a/net/dcsctp/public/strong_alias.h +++ b/net/dcsctp/public/strong_alias.h @@ -67,15 +67,6 @@ class StrongAlias { return value_ >= other.value_; } - // Hasher to use in std::unordered_map, std::unordered_set, etc. - struct Hasher { - using argument_type = StrongAlias; - using result_type = std::size_t; - result_type operator()(const argument_type& id) const { - return std::hash()(id.value()); - } - }; - protected: UnderlyingType value_; }; diff --git a/net/dcsctp/public/strong_alias_test.cc b/net/dcsctp/public/strong_alias_test.cc index cacb49dcb4..63aa60995c 100644 --- a/net/dcsctp/public/strong_alias_test.cc +++ b/net/dcsctp/public/strong_alias_test.cc @@ -15,9 +15,9 @@ #include #include #include -#include #include +#include "rtc_base/containers/flat_map.h" #include "rtc_base/gunit.h" #include "test/gmock.h" @@ -280,9 +280,9 @@ TEST(StrongAliasTest, CanWrapComplexStructures) { // namespace. So we can't print ComplexAlias. } -TYPED_TEST(StrongAliasTest, CanBeKeysInStdUnorderedMap) { +TYPED_TEST(StrongAliasTest, CanBeKeysInFlatMap) { using FooAlias = StrongAlias; - std::unordered_map map; + webrtc::flat_map map; FooAlias k1(GetExampleValue(0)); FooAlias k2(GetExampleValue(1)); diff --git a/net/dcsctp/rx/traditional_reassembly_streams.cc b/net/dcsctp/rx/traditional_reassembly_streams.cc index 7cec1150d5..4108d37236 100644 --- a/net/dcsctp/rx/traditional_reassembly_streams.cc +++ b/net/dcsctp/rx/traditional_reassembly_streams.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/net/dcsctp/rx/traditional_reassembly_streams.h b/net/dcsctp/rx/traditional_reassembly_streams.h index 12d1d933a4..d7ae2dd1b3 100644 --- a/net/dcsctp/rx/traditional_reassembly_streams.h +++ b/net/dcsctp/rx/traditional_reassembly_streams.h @@ -14,7 +14,6 @@ #include #include -#include #include "absl/strings/string_view.h" #include "api/array_view.h" @@ -108,10 +107,8 @@ class TraditionalReassemblyStreams : public ReassemblyStreams { const OnAssembledMessage on_assembled_message_; // All unordered and ordered streams, managing not-yet-assembled data. - std::unordered_map - unordered_streams_; - std::unordered_map - ordered_streams_; + std::map unordered_streams_; + std::map ordered_streams_; }; } // namespace dcsctp diff --git a/net/dcsctp/socket/BUILD.gn b/net/dcsctp/socket/BUILD.gn index 805c6779b9..895292001c 100644 --- a/net/dcsctp/socket/BUILD.gn +++ b/net/dcsctp/socket/BUILD.gn @@ -52,6 +52,7 @@ rtc_library("stream_reset_handler") { "../../../rtc_base", "../../../rtc_base:checks", "../../../rtc_base:rtc_base_approved", + "../../../rtc_base/containers:flat_set", "../common:internal_types", "../common:str_join", "../packet:chunk", diff --git a/net/dcsctp/socket/stream_reset_handler.cc b/net/dcsctp/socket/stream_reset_handler.cc index a1f57e6b2b..40cb8f6166 100644 --- a/net/dcsctp/socket/stream_reset_handler.cc +++ b/net/dcsctp/socket/stream_reset_handler.cc @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/net/dcsctp/socket/stream_reset_handler.h b/net/dcsctp/socket/stream_reset_handler.h index fe01ac7c43..7f72889356 100644 --- a/net/dcsctp/socket/stream_reset_handler.h +++ b/net/dcsctp/socket/stream_reset_handler.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -33,6 +32,7 @@ #include "net/dcsctp/socket/context.h" #include "net/dcsctp/timer/timer.h" #include "net/dcsctp/tx/retransmission_queue.h" +#include "rtc_base/containers/flat_set.h" namespace dcsctp { @@ -207,7 +207,7 @@ class StreamResetHandler { // Outgoing streams that have been requested to be reset, but hasn't yet // been included in an outgoing request. - std::unordered_set streams_to_reset_; + webrtc::flat_set streams_to_reset_; // The next sequence number for outgoing stream requests. ReconfigRequestSN next_outgoing_req_seq_nbr_; diff --git a/net/dcsctp/timer/BUILD.gn b/net/dcsctp/timer/BUILD.gn index a0ba5b030e..286bbe9cf5 100644 --- a/net/dcsctp/timer/BUILD.gn +++ b/net/dcsctp/timer/BUILD.gn @@ -14,6 +14,8 @@ rtc_library("timer") { "../../../rtc_base", "../../../rtc_base:checks", "../../../rtc_base:rtc_base_approved", + "../../../rtc_base/containers:flat_map", + "../../../rtc_base/containers:flat_set", "../public:socket", "../public:strong_alias", "../public:types", diff --git a/net/dcsctp/timer/fake_timeout.h b/net/dcsctp/timer/fake_timeout.h index 927e6b2808..f2bf10325e 100644 --- a/net/dcsctp/timer/fake_timeout.h +++ b/net/dcsctp/timer/fake_timeout.h @@ -14,13 +14,13 @@ #include #include #include -#include #include #include #include "absl/types/optional.h" #include "net/dcsctp/public/timeout.h" #include "rtc_base/checks.h" +#include "rtc_base/containers/flat_set.h" namespace dcsctp { @@ -93,7 +93,7 @@ class FakeTimeoutManager { private: const std::function get_time_; - std::unordered_set timers_; + webrtc::flat_set timers_; }; } // namespace dcsctp diff --git a/net/dcsctp/timer/timer.cc b/net/dcsctp/timer/timer.cc index 593d639fa7..8f64533d47 100644 --- a/net/dcsctp/timer/timer.cc +++ b/net/dcsctp/timer/timer.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include "absl/memory/memory.h" diff --git a/net/dcsctp/timer/timer.h b/net/dcsctp/timer/timer.h index bf923ea4ca..2010b23a77 100644 --- a/net/dcsctp/timer/timer.h +++ b/net/dcsctp/timer/timer.h @@ -14,9 +14,9 @@ #include #include +#include #include #include -#include #include #include "absl/strings/string_view.h" @@ -176,7 +176,7 @@ class TimerManager { private: const std::function()> create_timeout_; - std::unordered_map timers_; + std::map timers_; TimerID next_id_ = TimerID(0); }; diff --git a/net/dcsctp/tx/BUILD.gn b/net/dcsctp/tx/BUILD.gn index 2f0b27afc6..50e424cc25 100644 --- a/net/dcsctp/tx/BUILD.gn +++ b/net/dcsctp/tx/BUILD.gn @@ -26,7 +26,6 @@ rtc_library("rr_send_queue") { "../../../api:array_view", "../../../rtc_base:checks", "../../../rtc_base:rtc_base_approved", - "../common:pair_hash", "../packet:data", "../public:socket", "../public:types", @@ -76,7 +75,6 @@ rtc_library("retransmission_queue") { "../../../rtc_base:checks", "../../../rtc_base:rtc_base_approved", "../common:math", - "../common:pair_hash", "../common:sequence_numbers", "../common:str_join", "../packet:chunk", diff --git a/net/dcsctp/tx/retransmission_queue.cc b/net/dcsctp/tx/retransmission_queue.cc index d73616eaf0..0156a56c96 100644 --- a/net/dcsctp/tx/retransmission_queue.cc +++ b/net/dcsctp/tx/retransmission_queue.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -25,7 +24,6 @@ #include "absl/types/optional.h" #include "api/array_view.h" #include "net/dcsctp/common/math.h" -#include "net/dcsctp/common/pair_hash.h" #include "net/dcsctp/common/sequence_numbers.h" #include "net/dcsctp/common/str_join.h" #include "net/dcsctp/packet/chunk/data_chunk.h" @@ -846,8 +844,7 @@ size_t RetransmissionQueue::max_bytes_to_send() const { } ForwardTsnChunk RetransmissionQueue::CreateForwardTsn() const { - std::unordered_map - skipped_per_ordered_stream; + std::map skipped_per_ordered_stream; UnwrappedTSN new_cumulative_ack = last_cumulative_tsn_ack_; for (const auto& elem : outstanding_data_) { @@ -873,8 +870,7 @@ ForwardTsnChunk RetransmissionQueue::CreateForwardTsn() const { } IForwardTsnChunk RetransmissionQueue::CreateIForwardTsn() const { - std::unordered_map, MID, UnorderedStreamHash> - skipped_per_stream; + std::map, MID> skipped_per_stream; UnwrappedTSN new_cumulative_ack = last_cumulative_tsn_ack_; for (const auto& elem : outstanding_data_) { diff --git a/net/dcsctp/tx/rr_send_queue.h b/net/dcsctp/tx/rr_send_queue.h index 3ec45af17d..ed077cdef7 100644 --- a/net/dcsctp/tx/rr_send_queue.h +++ b/net/dcsctp/tx/rr_send_queue.h @@ -20,7 +20,6 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/array_view.h" -#include "net/dcsctp/common/pair_hash.h" #include "net/dcsctp/public/dcsctp_message.h" #include "net/dcsctp/public/dcsctp_socket.h" #include "net/dcsctp/public/types.h"