-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[ADT] Skip destroying trivially destructible values in DenseMap #106934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[ADT] Skip destroying trivially destructible values in DenseMap #106934
Conversation
@llvm/pr-subscribers-llvm-adt Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/106934.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index f71cd5b4771b75..68f3f1defc2bd0 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -392,6 +392,11 @@ class DenseMapBase : public DebugEpochBase {
DenseMapBase() = default;
void destroyAll() {
+ // Don't bother destroying trivially destructible stuff.
+ if constexpr (std::is_trivially_destructible_v<KeyT> &&
+ std::is_trivially_destructible_v<ValueT>)
+ return;
+
if (getNumBuckets() == 0) // Nothing to do.
return;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine in isolation, but I wonder if we do have a test that makes sure that non-trivial destructors get run?
Let me come up with some tests. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test?
Not sure this is testable? If they're trivially destructible, it wouldn't be possible to observe the difference between destroying them and not destroying them, right? |
We could have the test for the non-trivially destructible case to make sure we don't unintentionally skip destructors. If we already do, it would be good to point out in the PR description. |
Sure, that'd be nice - good call. |
No description provided.