Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/TemporaryChange.h |
| diff --git a/third_party/WebKit/Source/wtf/TemporaryChange.h b/third_party/WebKit/Source/wtf/TemporaryChange.h |
| index a0ab5b154e210d29035baf84e1c9f4ec1a7cb72b..e6d7150bf62935d26849e6ae74932b262ed96d4b 100644 |
| --- a/third_party/WebKit/Source/wtf/TemporaryChange.h |
| +++ b/third_party/WebKit/Source/wtf/TemporaryChange.h |
| @@ -26,40 +26,14 @@ |
| #ifndef TemporaryChange_h |
| #define TemporaryChange_h |
| -#include "wtf/Noncopyable.h" |
| +#include "base/auto_reset.h" |
| namespace WTF { |
| -// TemporaryChange<> is useful for setting a variable to a new value only within a |
| -// particular scope. An TemporaryChange<> object changes a variable to its original |
| -// value upon destruction, making it an alternative to writing "var = false;" |
| -// or "var = oldVal;" at all of a block's exit points. |
| -// |
| -// This should be obvious, but note that an TemporaryChange<> instance should have a |
| -// shorter lifetime than its scopedVariable, to prevent invalid memory writes |
| -// when the TemporaryChange<> object is destroyed. |
| +// WTF::TemporaryChange is base::AutoReset. See base/auto_reset.h for documentation. |
| -template<typename T> |
| -class TemporaryChange { |
| - WTF_MAKE_NONCOPYABLE(TemporaryChange); |
| -public: |
| - TemporaryChange(T& scopedVariable, T newValue) |
| - : m_scopedVariable(scopedVariable) |
| - , m_originalValue(scopedVariable) |
| - { |
| - m_scopedVariable = newValue; |
| - } |
| - |
| - ~TemporaryChange() |
| - { |
| - m_scopedVariable = m_originalValue; |
| - } |
| - |
| - |
| -private: |
| - T& m_scopedVariable; |
| - T m_originalValue; |
| -}; |
| +template <typename T> |
| +using TemporaryChange = typename base::AutoReset<T>; |
|
Yuta Kitamura
2016/07/15 03:04:41
A compiler in my brain tells this "typename" is un
jsbell
2016/07/18 18:42:37
Copy/pasta. Will remove.
|
| } // namespace WTF |