Use absl::flat_hash_set and absl::flat_hash_map in dawn/wire
Bug: dawn:1513
Change-Id: Ia09c85fbfee835582bb9276625b687a0911f12cd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/167124
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/wire/BUILD.gn b/src/dawn/wire/BUILD.gn
index 13ba0ba..1fd51cb 100644
--- a/src/dawn/wire/BUILD.gn
+++ b/src/dawn/wire/BUILD.gn
@@ -61,6 +61,20 @@
]
}
+group("abseil") {
+ # When build_with_chromium=true we need to include "//third_party/abseil-cpp:absl" while
+ # it's beneficial to be more specific with standalone Dawn, especially when it comes to
+ # including it as a dependency in other projects (such as Skia).
+ if (build_with_chromium) {
+ public_deps = [ "$dawn_abseil_dir:absl" ]
+ } else {
+ public_deps = [
+ "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_map",
+ "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_set",
+ ]
+ }
+}
+
dawn_component("wire") {
DEFINE_PREFIX = "DAWN_WIRE"
@@ -134,5 +148,8 @@
]
# Make headers publicly visible
- public_deps = [ ":headers" ]
+ public_deps = [
+ ":abseil",
+ ":headers",
+ ]
}
diff --git a/src/dawn/wire/CMakeLists.txt b/src/dawn/wire/CMakeLists.txt
index ab63f04..bf709e0 100644
--- a/src/dawn/wire/CMakeLists.txt
+++ b/src/dawn/wire/CMakeLists.txt
@@ -108,7 +108,7 @@
)
target_link_libraries(dawn_wire
PUBLIC dawn_headers
- PRIVATE dawn_common dawn_internal_config
+ PRIVATE dawn_common dawn_internal_config absl_flat_hash_map absl_flat_hash_set
)
install_if_enabled(dawn_wire)
diff --git a/src/dawn/wire/client/Client.cpp b/src/dawn/wire/client/Client.cpp
index 32d78d2..24e098a 100644
--- a/src/dawn/wire/client/Client.cpp
+++ b/src/dawn/wire/client/Client.cpp
@@ -138,8 +138,8 @@
}
// Reserve an EventManager for the given instance and make the association in the map.
- mEventManagers[ObjectHandle(instance->GetWireId(), instance->GetWireGeneration())] =
- std::make_unique<EventManager>();
+ mEventManagers.emplace(ObjectHandle(instance->GetWireId(), instance->GetWireGeneration()),
+ std::make_unique<EventManager>());
ReservedInstance result;
result.instance = ToAPI(instance);
diff --git a/src/dawn/wire/client/Client.h b/src/dawn/wire/client/Client.h
index 833cdba..a4a82c1 100644
--- a/src/dawn/wire/client/Client.h
+++ b/src/dawn/wire/client/Client.h
@@ -29,9 +29,9 @@
#define SRC_DAWN_WIRE_CLIENT_CLIENT_H_
#include <memory>
-#include <unordered_map>
#include <utility>
+#include "absl/container/flat_hash_map.h"
#include "dawn/common/LinkedList.h"
#include "dawn/common/NonCopyable.h"
#include "dawn/webgpu.h"
@@ -130,7 +130,7 @@
// instances. We also cannot currently store the EventManger on the Instance because
// spontaneous mode callbacks outlive the instance. We also can't reuse the ObjectStore for the
// EventManagers because we need to track old instance handles even after they are reclaimed.
- std::unordered_map<ObjectHandle, std::unique_ptr<EventManager>> mEventManagers;
+ absl::flat_hash_map<ObjectHandle, std::unique_ptr<EventManager>> mEventManagers;
bool mDisconnected = false;
};
diff --git a/src/dawn/wire/client/Instance.cpp b/src/dawn/wire/client/Instance.cpp
index 280ea4b..db7907d 100644
--- a/src/dawn/wire/client/Instance.cpp
+++ b/src/dawn/wire/client/Instance.cpp
@@ -314,7 +314,7 @@
}
bool Instance::HasWGSLLanguageFeature(WGPUWGSLFeatureName feature) const {
- return mWGSLFeatures.count(feature) != 0;
+ return mWGSLFeatures.contains(feature);
}
size_t Instance::EnumerateWGSLLanguageFeatures(WGPUWGSLFeatureName* features) const {
diff --git a/src/dawn/wire/client/Instance.h b/src/dawn/wire/client/Instance.h
index 43301ef..291c67c 100644
--- a/src/dawn/wire/client/Instance.h
+++ b/src/dawn/wire/client/Instance.h
@@ -28,8 +28,7 @@
#ifndef SRC_DAWN_WIRE_CLIENT_INSTANCE_H_
#define SRC_DAWN_WIRE_CLIENT_INSTANCE_H_
-#include <unordered_set>
-
+#include "absl/container/flat_hash_set.h"
#include "dawn/webgpu.h"
#include "dawn/wire/WireClient.h"
#include "dawn/wire/WireCmd_autogen.h"
@@ -66,7 +65,7 @@
void GatherWGSLFeatures(const WGPUDawnWireWGSLControl* wgslControl,
const WGPUDawnWGSLBlocklist* wgslBlocklist);
- std::unordered_set<WGPUWGSLFeatureName> mWGSLFeatures;
+ absl::flat_hash_set<WGPUWGSLFeatureName> mWGSLFeatures;
};
} // namespace dawn::wire::client
diff --git a/src/dawn/wire/client/LimitsAndFeatures.cpp b/src/dawn/wire/client/LimitsAndFeatures.cpp
index 549e8fc..0fe29d5 100644
--- a/src/dawn/wire/client/LimitsAndFeatures.cpp
+++ b/src/dawn/wire/client/LimitsAndFeatures.cpp
@@ -64,7 +64,7 @@
}
bool LimitsAndFeatures::HasFeature(WGPUFeatureName feature) const {
- return mFeatures.count(feature) != 0;
+ return mFeatures.contains(feature);
}
size_t LimitsAndFeatures::EnumerateFeatures(WGPUFeatureName* features) const {
diff --git a/src/dawn/wire/client/LimitsAndFeatures.h b/src/dawn/wire/client/LimitsAndFeatures.h
index 026ec27..6c6e6c7 100644
--- a/src/dawn/wire/client/LimitsAndFeatures.h
+++ b/src/dawn/wire/client/LimitsAndFeatures.h
@@ -28,8 +28,7 @@
#ifndef SRC_DAWN_WIRE_CLIENT_LIMITSANDFEATURES_H_
#define SRC_DAWN_WIRE_CLIENT_LIMITSANDFEATURES_H_
-#include <unordered_set>
-
+#include "absl/container/flat_hash_set.h"
#include "dawn/webgpu.h"
namespace dawn::wire::client {
@@ -49,7 +48,7 @@
private:
WGPUSupportedLimits mLimits;
WGPUDawnExperimentalSubgroupLimits mExperimentalSubgroupLimits;
- std::unordered_set<WGPUFeatureName> mFeatures;
+ absl::flat_hash_set<WGPUFeatureName> mFeatures;
};
} // namespace dawn::wire::client
diff --git a/src/dawn/wire/server/ObjectStorage.h b/src/dawn/wire/server/ObjectStorage.h
index ac1cf1e..13b5705 100644
--- a/src/dawn/wire/server/ObjectStorage.h
+++ b/src/dawn/wire/server/ObjectStorage.h
@@ -31,10 +31,10 @@
#include <algorithm>
#include <map>
#include <memory>
-#include <unordered_set>
#include <utility>
#include <vector>
+#include "absl/container/flat_hash_set.h"
#include "dawn/wire/WireCmd_autogen.h"
#include "dawn/wire/WireServer.h"
@@ -263,7 +263,7 @@
KnownObjectsBase<WGPUDevice>::Free(id);
}
- bool IsKnown(WGPUDevice device) const { return mKnownSet.count(device) != 0; }
+ bool IsKnown(WGPUDevice device) const { return mKnownSet.contains(device); }
private:
void AddToKnownSet(Known<WGPUDevice> device) {
@@ -271,7 +271,7 @@
mKnownSet.insert(device->handle);
}
}
- std::unordered_set<WGPUDevice> mKnownSet;
+ absl::flat_hash_set<WGPUDevice> mKnownSet;
};
} // namespace dawn::wire::server