Stop using ScopeGuardImpl in DynamicParser
authorYedidya Feldblum <yfeldblum@fb.com>
Thu, 11 Jan 2018 01:52:11 +0000 (17:52 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 11 Jan 2018 02:20:14 +0000 (18:20 -0800)
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
folly/experimental/DynamicParser.cpp
folly/experimental/DynamicParser.h
folly/experimental/test/DynamicParserTest.cpp

index 4430e29c778c93fdaf689e17e5dc470efd21a6e8..f3459223c9fa242783876163b4ed5148aa0fcc22 100644 (file)
@@ -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.
index 9c9031791fa77b462c42ff44fa567a7d5373b62c..6e07ff71f1c0891c807efd764561389cf14b4892 100644 (file)
@@ -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::Pop>
-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<DynamicParser::ParserStack::Pop> 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.
index 57a53752ec03f4a1faadbae7bef77bf05e8d2934..c4ed5e07282593ab84011b1b2926eb75a9c681ac 100644 (file)
@@ -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> 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<Pop> 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;
index dbf080cb9004949bf4d3e9517bb3f5a28fbe6e56..0979ad8b86f40086afcbf6889eb977e049b6bca5 100644 (file)
@@ -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.