From 5277a636b62a8f9c80756012de9bae80358ee30e Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 10 Jan 2018 17:52:11 -0800 Subject: [PATCH] Stop using ScopeGuardImpl in DynamicParser Summary: [Folly] Stop using `ScopeGuardImpl` in `DynamicParser`. `ScopeGuardImpl` is an impl type that should not be treated as public. Reviewed By: igorsugak Differential Revision: D6689835 fbshipit-source-id: aea6c985e40887594c0aeb0c0948fa77c149a89b --- folly/experimental/DynamicParser-inl.h | 2 +- folly/experimental/DynamicParser.cpp | 9 +++------ folly/experimental/DynamicParser.h | 15 +++++++++++---- folly/experimental/test/DynamicParserTest.cpp | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/folly/experimental/DynamicParser-inl.h b/folly/experimental/DynamicParser-inl.h index 4430e29c..f3459223 100644 --- a/folly/experimental/DynamicParser-inl.h +++ b/folly/experimental/DynamicParser-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/folly/experimental/DynamicParser.cpp b/folly/experimental/DynamicParser.cpp index 9c903179..6e07ff71 100644 --- a/folly/experimental/DynamicParser.cpp +++ b/folly/experimental/DynamicParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,14 +117,11 @@ void DynamicParser::ParserStack::Pop::operator()() noexcept { } } -folly::ScopeGuardImpl -DynamicParser::ParserStack::push( +DynamicParser::ParserStack::PopGuard DynamicParser::ParserStack::push( const folly::dynamic& k, const folly::dynamic& v) noexcept { // Save the previous state of the parser. - folly::ScopeGuardImpl guard( - DynamicParser::ParserStack::Pop(this) - ); + DynamicParser::ParserStack::PopGuard guard{this}; key_ = &k; value_ = &v; // We create errors_ sub-objects lazily to keep the result small. diff --git a/folly/experimental/DynamicParser.h b/folly/experimental/DynamicParser.h index 57a53752..c4ed5e07 100644 --- a/folly/experimental/DynamicParser.h +++ b/folly/experimental/DynamicParser.h @@ -1,5 +1,5 @@ /* - * Copyright 2017-present Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -328,6 +328,15 @@ class DynamicParser { const folly::dynamic* value_; ParserStack* stackPtr_; }; + struct PopGuard { + explicit PopGuard(ParserStack* sp) : pop_(in_place, sp) {} + ~PopGuard() { + pop_ && ((*pop_)(), true); + } + + private: + Optional pop_; + }; explicit ParserStack(const folly::dynamic* input) : value_(input), @@ -343,9 +352,7 @@ class DynamicParser { // Lets user code nest parser calls by recording current key+value and // returning an RAII guard to restore the old one. `noexcept` since it // is used unwrapped. - folly::ScopeGuardImpl push( - const folly::dynamic& k, const folly::dynamic& v - ) noexcept; + PopGuard push(const folly::dynamic& k, const folly::dynamic& v) noexcept; // Throws DynamicParserLogicError if used outside of a parsing function. inline const folly::dynamic& key() const; diff --git a/folly/experimental/test/DynamicParserTest.cpp b/folly/experimental/test/DynamicParserTest.cpp index dbf080cb..0979ad8b 100644 --- a/folly/experimental/test/DynamicParserTest.cpp +++ b/folly/experimental/test/DynamicParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- 2.34.1