Commit 5277a636 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

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
parent 7bf14860
/* /*
* Copyright 2017 Facebook, Inc. * Copyright 2016-present Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2017 Facebook, Inc. * Copyright 2016-present Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -117,14 +117,11 @@ void DynamicParser::ParserStack::Pop::operator()() noexcept { ...@@ -117,14 +117,11 @@ void DynamicParser::ParserStack::Pop::operator()() noexcept {
} }
} }
folly::ScopeGuardImpl<DynamicParser::ParserStack::Pop> DynamicParser::ParserStack::PopGuard DynamicParser::ParserStack::push(
DynamicParser::ParserStack::push(
const folly::dynamic& k, const folly::dynamic& k,
const folly::dynamic& v) noexcept { const folly::dynamic& v) noexcept {
// Save the previous state of the parser. // Save the previous state of the parser.
folly::ScopeGuardImpl<DynamicParser::ParserStack::Pop> guard( DynamicParser::ParserStack::PopGuard guard{this};
DynamicParser::ParserStack::Pop(this)
);
key_ = &k; key_ = &k;
value_ = &v; value_ = &v;
// We create errors_ sub-objects lazily to keep the result small. // We create errors_ sub-objects lazily to keep the result small.
......
/* /*
* Copyright 2017-present Facebook, Inc. * Copyright 2016-present Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -328,6 +328,15 @@ class DynamicParser { ...@@ -328,6 +328,15 @@ class DynamicParser {
const folly::dynamic* value_; const folly::dynamic* value_;
ParserStack* stackPtr_; 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) explicit ParserStack(const folly::dynamic* input)
: value_(input), : value_(input),
...@@ -343,9 +352,7 @@ class DynamicParser { ...@@ -343,9 +352,7 @@ class DynamicParser {
// Lets user code nest parser calls by recording current key+value and // Lets user code nest parser calls by recording current key+value and
// returning an RAII guard to restore the old one. `noexcept` since it // returning an RAII guard to restore the old one. `noexcept` since it
// is used unwrapped. // is used unwrapped.
folly::ScopeGuardImpl<Pop> push( PopGuard push(const folly::dynamic& k, const folly::dynamic& v) noexcept;
const folly::dynamic& k, const folly::dynamic& v
) noexcept;
// Throws DynamicParserLogicError if used outside of a parsing function. // Throws DynamicParserLogicError if used outside of a parsing function.
inline const folly::dynamic& key() const; inline const folly::dynamic& key() const;
......
/* /*
* Copyright 2017 Facebook, Inc. * Copyright 2016-present Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment