[PATCH] D120673: [demangler] Simplify SwapAndRestore
Nathan Sidwell via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 28 12:18:20 PST 2022
urnathan created this revision.
urnathan added reviewers: iains, ChuanqiXu.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The SwapAndRestore class is over engineered. Nothing makes use of the early restoration machinery. Let's just remove that cognitive burden.
https://reviews.llvm.org/D120673
Files:
libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h
Index: llvm/include/llvm/Demangle/Utility.h
===================================================================
--- llvm/include/llvm/Demangle/Utility.h
+++ llvm/include/llvm/Demangle/Utility.h
@@ -163,7 +163,6 @@
template <class T> class SwapAndRestore {
T &Restore;
T OriginalValue;
- bool ShouldRestore = true;
public:
SwapAndRestore(T &Restore_) : SwapAndRestore(Restore_, Restore_) {}
@@ -173,18 +172,7 @@
Restore = std::move(NewVal);
}
~SwapAndRestore() {
- if (ShouldRestore)
- Restore = std::move(OriginalValue);
- }
-
- void shouldRestore(bool ShouldRestore_) { ShouldRestore = ShouldRestore_; }
-
- void restoreNow(bool Force) {
- if (!Force && !ShouldRestore)
- return;
-
Restore = std::move(OriginalValue);
- ShouldRestore = false;
}
SwapAndRestore(const SwapAndRestore &) = delete;
Index: libcxxabi/src/demangle/Utility.h
===================================================================
--- libcxxabi/src/demangle/Utility.h
+++ libcxxabi/src/demangle/Utility.h
@@ -163,7 +163,6 @@
template <class T> class SwapAndRestore {
T &Restore;
T OriginalValue;
- bool ShouldRestore = true;
public:
SwapAndRestore(T &Restore_) : SwapAndRestore(Restore_, Restore_) {}
@@ -173,18 +172,7 @@
Restore = std::move(NewVal);
}
~SwapAndRestore() {
- if (ShouldRestore)
- Restore = std::move(OriginalValue);
- }
-
- void shouldRestore(bool ShouldRestore_) { ShouldRestore = ShouldRestore_; }
-
- void restoreNow(bool Force) {
- if (!Force && !ShouldRestore)
- return;
-
Restore = std::move(OriginalValue);
- ShouldRestore = false;
}
SwapAndRestore(const SwapAndRestore &) = delete;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120673.411863.patch
Type: text/x-patch
Size: 1698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220228/cf0289a9/attachment.bin>
More information about the llvm-commits
mailing list