Commit 95c7d18c authored by TJ Yin's avatar TJ Yin Committed by Facebook Github Bot

Replace folly::Optional::clear() by reset()

Reviewed By: yfeldblum

Differential Revision: D19953637

fbshipit-source-id: c2135fc24084b7bba0c9d6fc978c8b6c8f9943d4
parent 19f6ae0d
...@@ -1171,11 +1171,11 @@ LZMA2StreamCodec::LZMA2StreamCodec(int level, CodecType type) ...@@ -1171,11 +1171,11 @@ LZMA2StreamCodec::LZMA2StreamCodec(int level, CodecType type)
LZMA2StreamCodec::~LZMA2StreamCodec() { LZMA2StreamCodec::~LZMA2StreamCodec() {
if (cstream_) { if (cstream_) {
lzma_end(cstream_.get_pointer()); lzma_end(cstream_.get_pointer());
cstream_.clear(); cstream_.reset();
} }
if (dstream_) { if (dstream_) {
lzma_end(dstream_.get_pointer()); lzma_end(dstream_.get_pointer());
dstream_.clear(); dstream_.reset();
} }
} }
...@@ -1578,11 +1578,11 @@ int bzCheck(int const rc) { ...@@ -1578,11 +1578,11 @@ int bzCheck(int const rc) {
Bzip2StreamCodec::~Bzip2StreamCodec() { Bzip2StreamCodec::~Bzip2StreamCodec() {
if (cstream_) { if (cstream_) {
BZ2_bzCompressEnd(cstream_.get_pointer()); BZ2_bzCompressEnd(cstream_.get_pointer());
cstream_.clear(); cstream_.reset();
} }
if (dstream_) { if (dstream_) {
BZ2_bzDecompressEnd(dstream_.get_pointer()); BZ2_bzDecompressEnd(dstream_.get_pointer());
dstream_.clear(); dstream_.reset();
} }
} }
......
...@@ -244,11 +244,11 @@ ZlibStreamCodec::ZlibStreamCodec(Options options, int level) ...@@ -244,11 +244,11 @@ ZlibStreamCodec::ZlibStreamCodec(Options options, int level)
ZlibStreamCodec::~ZlibStreamCodec() { ZlibStreamCodec::~ZlibStreamCodec() {
if (deflateStream_) { if (deflateStream_) {
deflateEnd(deflateStream_.get_pointer()); deflateEnd(deflateStream_.get_pointer());
deflateStream_.clear(); deflateStream_.reset();
} }
if (inflateStream_) { if (inflateStream_) {
inflateEnd(inflateStream_.get_pointer()); inflateEnd(inflateStream_.get_pointer());
inflateStream_.clear(); inflateStream_.reset();
} }
} }
...@@ -260,7 +260,7 @@ void ZlibStreamCodec::resetDeflateStream() { ...@@ -260,7 +260,7 @@ void ZlibStreamCodec::resetDeflateStream() {
if (deflateStream_) { if (deflateStream_) {
int const rc = deflateReset(deflateStream_.get_pointer()); int const rc = deflateReset(deflateStream_.get_pointer());
if (rc != Z_OK) { if (rc != Z_OK) {
deflateStream_.clear(); deflateStream_.reset();
throw std::runtime_error( throw std::runtime_error(
to<std::string>("ZlibStreamCodec: deflateReset error: ", rc)); to<std::string>("ZlibStreamCodec: deflateReset error: ", rc));
} }
...@@ -283,7 +283,7 @@ void ZlibStreamCodec::resetDeflateStream() { ...@@ -283,7 +283,7 @@ void ZlibStreamCodec::resetDeflateStream() {
options_.memLevel, options_.memLevel,
options_.strategy); options_.strategy);
if (rc != Z_OK) { if (rc != Z_OK) {
deflateStream_.clear(); deflateStream_.reset();
throw std::runtime_error( throw std::runtime_error(
to<std::string>("ZlibStreamCodec: deflateInit error: ", rc)); to<std::string>("ZlibStreamCodec: deflateInit error: ", rc));
} }
...@@ -293,7 +293,7 @@ void ZlibStreamCodec::resetInflateStream() { ...@@ -293,7 +293,7 @@ void ZlibStreamCodec::resetInflateStream() {
if (inflateStream_) { if (inflateStream_) {
int const rc = inflateReset(inflateStream_.get_pointer()); int const rc = inflateReset(inflateStream_.get_pointer());
if (rc != Z_OK) { if (rc != Z_OK) {
inflateStream_.clear(); inflateStream_.reset();
throw std::runtime_error( throw std::runtime_error(
to<std::string>("ZlibStreamCodec: inflateReset error: ", rc)); to<std::string>("ZlibStreamCodec: inflateReset error: ", rc));
} }
...@@ -304,7 +304,7 @@ void ZlibStreamCodec::resetInflateStream() { ...@@ -304,7 +304,7 @@ void ZlibStreamCodec::resetInflateStream() {
inflateStream_.get_pointer(), inflateStream_.get_pointer(),
getWindowBits(options_.format, options_.windowSize)); getWindowBits(options_.format, options_.windowSize));
if (rc != Z_OK) { if (rc != Z_OK) {
inflateStream_.clear(); inflateStream_.reset();
throw std::runtime_error( throw std::runtime_error(
to<std::string>("ZlibStreamCodec: inflateInit error: ", rc)); to<std::string>("ZlibStreamCodec: inflateInit error: ", rc));
} }
......
...@@ -413,7 +413,7 @@ TEST(Util, callWithConstructedKey) { ...@@ -413,7 +413,7 @@ TEST(Util, callWithConstructedKey) {
Tracked<0> k1{0}; Tracked<0> k1{0};
Tracked<0> k2{0}; Tracked<0> k2{0};
uint64_t k3 = 0; uint64_t k3 = 0;
sink.clear(); sink.reset();
resetTracking(); resetTracking();
detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc, k1); detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc, k1);
// copy is expected on successful emplace // copy is expected on successful emplace
...@@ -429,7 +429,7 @@ TEST(Util, callWithConstructedKey) { ...@@ -429,7 +429,7 @@ TEST(Util, callWithConstructedKey) {
// copy convert expected for failing emplace with wrong type // copy convert expected for failing emplace with wrong type
EXPECT_EQ(Tracked<0>::counts().dist(Counts{0, 0, 1, 0}), 0); EXPECT_EQ(Tracked<0>::counts().dist(Counts{0, 0, 1, 0}), 0);
sink.clear(); sink.reset();
resetTracking(); resetTracking();
detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc, k3); detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc, k3);
// copy convert + move expected for successful emplace with wrong type // copy convert + move expected for successful emplace with wrong type
...@@ -439,7 +439,7 @@ TEST(Util, callWithConstructedKey) { ...@@ -439,7 +439,7 @@ TEST(Util, callWithConstructedKey) {
Tracked<0> k1{0}; Tracked<0> k1{0};
Tracked<0> k2{0}; Tracked<0> k2{0};
uint64_t k3 = 0; uint64_t k3 = 0;
sink.clear(); sink.reset();
resetTracking(); resetTracking();
detail::callWithConstructedKey<Tracked<0>, FalseFunc1>( detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(
a, sinkFunc, std::move(k1)); a, sinkFunc, std::move(k1));
...@@ -458,7 +458,7 @@ TEST(Util, callWithConstructedKey) { ...@@ -458,7 +458,7 @@ TEST(Util, callWithConstructedKey) {
// move convert expected for failing emplace with wrong type // move convert expected for failing emplace with wrong type
EXPECT_EQ(Tracked<0>::counts().dist(Counts{0, 0, 0, 1}), 0); EXPECT_EQ(Tracked<0>::counts().dist(Counts{0, 0, 0, 1}), 0);
sink.clear(); sink.reset();
resetTracking(); resetTracking();
detail::callWithConstructedKey<Tracked<0>, FalseFunc1>( detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(
a, sinkFunc, std::move(k3)); a, sinkFunc, std::move(k3));
...@@ -468,7 +468,7 @@ TEST(Util, callWithConstructedKey) { ...@@ -468,7 +468,7 @@ TEST(Util, callWithConstructedKey) {
// Calling the default pair constructor via emplace is valid, but not // Calling the default pair constructor via emplace is valid, but not
// very useful in real life. Verify that it works. // very useful in real life. Verify that it works.
sink.clear(); sink.reset();
detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc); detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc);
EXPECT_TRUE(sink.hasValue()); EXPECT_TRUE(sink.hasValue());
} }
......
...@@ -182,7 +182,7 @@ void destroy<IOThreadPoolExecutor>() { ...@@ -182,7 +182,7 @@ void destroy<IOThreadPoolExecutor>() {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
tpe->add(f); tpe->add(f);
} }
tpe.clear(); tpe.reset();
EXPECT_EQ(10, completed); EXPECT_EQ(10, completed);
} }
......
...@@ -74,10 +74,10 @@ TEST(EnvVarSaverTest, Movable) { ...@@ -74,10 +74,10 @@ TEST(EnvVarSaverTest, Movable) {
auto value = std::string{getenv(key)}; auto value = std::string{getenv(key)};
Optional<EnvVarSaver> pSaver2; Optional<EnvVarSaver> pSaver2;
pSaver2.emplace(std::move(*pSaver1)); pSaver2.emplace(std::move(*pSaver1));
pSaver1.clear(); pSaver1.reset();
PCHECK(0 == setenv(key, "blah", true)); PCHECK(0 == setenv(key, "blah", true));
EXPECT_STREQ("blah", getenv(key)); EXPECT_STREQ("blah", getenv(key));
pSaver2.clear(); pSaver2.reset();
EXPECT_EQ(value, getenv(key)); EXPECT_EQ(value, getenv(key));
} }
......
...@@ -44,7 +44,7 @@ class SimpleLoopController::SimpleTimeoutManager : public TimeoutManager { ...@@ -44,7 +44,7 @@ class SimpleLoopController::SimpleTimeoutManager : public TimeoutManager {
void cancelTimeout(AsyncTimeout* obj) final { void cancelTimeout(AsyncTimeout* obj) final {
CHECK(timeout_ && timeout_->first == obj); CHECK(timeout_ && timeout_->first == obj);
timeout_.clear(); timeout_.reset();
} }
void bumpHandlingTime() final {} void bumpHandlingTime() final {}
...@@ -60,7 +60,7 @@ class SimpleLoopController::SimpleTimeoutManager : public TimeoutManager { ...@@ -60,7 +60,7 @@ class SimpleLoopController::SimpleTimeoutManager : public TimeoutManager {
} }
auto* timeout = timeout_->first; auto* timeout = timeout_->first;
timeout_.clear(); timeout_.reset();
timeout->timeoutExpired(); timeout->timeoutExpired();
} }
......
...@@ -486,7 +486,7 @@ TEST_F(TimekeeperFixture, destruction) { ...@@ -486,7 +486,7 @@ TEST_F(TimekeeperFixture, destruction) {
tk.emplace(); tk.emplace();
auto f = tk->after(std::chrono::seconds(10)); auto f = tk->after(std::chrono::seconds(10));
EXPECT_FALSE(f.isReady()); EXPECT_FALSE(f.isReady());
tk.clear(); tk.reset();
EXPECT_TRUE(f.isReady()); EXPECT_TRUE(f.isReady());
EXPECT_TRUE(f.hasException()); EXPECT_TRUE(f.hasException());
} }
...@@ -1393,7 +1393,7 @@ TEST(Gen, Unwrap) { ...@@ -1393,7 +1393,7 @@ TEST(Gen, Unwrap) {
// oup's still-valid nullptr value wins here, the pointer to 7 doesn't apply // oup's still-valid nullptr value wins here, the pointer to 7 doesn't apply
EXPECT_FALSE(moved2); EXPECT_FALSE(moved2);
oup.clear(); oup.reset();
auto moved3 = std::move(oup) | unwrapOr(std::make_unique<int>(8)); auto moved3 = std::move(oup) | unwrapOr(std::make_unique<int>(8));
// oup is empty now, so the unwrapOr comes into play. // oup is empty now, so the unwrapOr comes into play.
EXPECT_TRUE(bool(moved3)); EXPECT_TRUE(bool(moved3));
...@@ -1444,7 +1444,7 @@ TEST(Gen, Unwrap) { ...@@ -1444,7 +1444,7 @@ TEST(Gen, Unwrap) {
EXPECT_TRUE(bool(opt)); // gutted value still present EXPECT_TRUE(bool(opt)); // gutted value still present
EXPECT_TRUE(bool(fallback.value())); // fallback value not needed EXPECT_TRUE(bool(fallback.value())); // fallback value not needed
opt.clear(); opt.reset();
EXPECT_FALSE(opt); // opt is empty now EXPECT_FALSE(opt); // opt is empty now
EXPECT_EQ(9, *(std::move(opt) | std::move(fallback))); EXPECT_EQ(9, *(std::move(opt) | std::move(fallback)));
......
...@@ -85,7 +85,7 @@ TEST_F(ScopedEventBaseThreadTest, eb_dtor_in_io_thread) { ...@@ -85,7 +85,7 @@ TEST_F(ScopedEventBaseThreadTest, eb_dtor_in_io_thread) {
auto const eb = sebt->getEventBase(); auto const eb = sebt->getEventBase();
thread::id eb_dtor_thread_id; thread::id eb_dtor_thread_id;
eb->runOnDestruction([&] { eb_dtor_thread_id = std::this_thread::get_id(); }); eb->runOnDestruction([&] { eb_dtor_thread_id = std::this_thread::get_id(); });
sebt.clear(); sebt.reset();
EXPECT_EQ(io_thread_id, eb_dtor_thread_id); EXPECT_EQ(io_thread_id, eb_dtor_thread_id);
} }
......
...@@ -183,7 +183,7 @@ TEST(CancellationTokenTest, CallbackThatDeregistersItself) { ...@@ -183,7 +183,7 @@ TEST(CancellationTokenTest, CallbackThatDeregistersItself) {
// Check that this doesn't deadlock when a callback tries to deregister // Check that this doesn't deadlock when a callback tries to deregister
// itself from within the callback. // itself from within the callback.
folly::Optional<CancellationCallback> callback; folly::Optional<CancellationCallback> callback;
callback.emplace(src.getToken(), [&] { callback.clear(); }); callback.emplace(src.getToken(), [&] { callback.reset(); });
src.requestCancellation(); src.requestCancellation();
} }
TEST(CancellationTokenTest, ManyCallbacks) { TEST(CancellationTokenTest, ManyCallbacks) {
......
...@@ -80,7 +80,7 @@ TEST(Optional, NoDefault) { ...@@ -80,7 +80,7 @@ TEST(Optional, NoDefault) {
EXPECT_FALSE(x); EXPECT_FALSE(x);
x.emplace(4, 5); x.emplace(4, 5);
EXPECT_TRUE(bool(x)); EXPECT_TRUE(bool(x));
x.clear(); x.reset();
EXPECT_FALSE(x); EXPECT_FALSE(x);
} }
...@@ -121,7 +121,7 @@ TEST(Optional, Const) { ...@@ -121,7 +121,7 @@ TEST(Optional, Const) {
EXPECT_EQ(*opt, 4); EXPECT_EQ(*opt, 4);
opt.emplace(5); opt.emplace(5);
EXPECT_EQ(*opt, 5); EXPECT_EQ(*opt, 5);
opt.clear(); opt.reset();
EXPECT_FALSE(bool(opt)); EXPECT_FALSE(bool(opt));
} }
{ // copy-constructed { // copy-constructed
...@@ -147,7 +147,7 @@ TEST(Optional, Simple) { ...@@ -147,7 +147,7 @@ TEST(Optional, Simple) {
EXPECT_EQ(4, opt.value_or(42)); EXPECT_EQ(4, opt.value_or(42));
opt = 5; opt = 5;
EXPECT_EQ(5, *opt); EXPECT_EQ(5, *opt);
opt.clear(); opt.reset();
EXPECT_FALSE(bool(opt)); EXPECT_FALSE(bool(opt));
} }
...@@ -260,14 +260,14 @@ TEST(Optional, InPlaceNestedConstruct) { ...@@ -260,14 +260,14 @@ TEST(Optional, InPlaceNestedConstruct) {
TEST(Optional, Unique) { TEST(Optional, Unique) {
Optional<unique_ptr<int>> opt; Optional<unique_ptr<int>> opt;
opt.clear(); opt.reset();
EXPECT_FALSE(bool(opt)); EXPECT_FALSE(bool(opt));
// empty->emplaced // empty->emplaced
opt.emplace(new int(5)); opt.emplace(new int(5));
EXPECT_TRUE(bool(opt)); EXPECT_TRUE(bool(opt));
EXPECT_EQ(5, **opt); EXPECT_EQ(5, **opt);
opt.clear(); opt.reset();
// empty->moved // empty->moved
opt = std::make_unique<int>(6); opt = std::make_unique<int>(6);
EXPECT_EQ(6, **opt); EXPECT_EQ(6, **opt);
...@@ -298,13 +298,13 @@ TEST(Optional, Shared) { ...@@ -298,13 +298,13 @@ TEST(Optional, Shared) {
ptr = opt.value(); ptr = opt.value();
EXPECT_EQ(ptr.get(), opt->get()); EXPECT_EQ(ptr.get(), opt->get());
EXPECT_EQ(2, ptr.use_count()); EXPECT_EQ(2, ptr.use_count());
opt.clear(); opt.reset();
EXPECT_EQ(1, ptr.use_count()); EXPECT_EQ(1, ptr.use_count());
// full->copied // full->copied
opt = ptr; opt = ptr;
EXPECT_EQ(2, ptr.use_count()); EXPECT_EQ(2, ptr.use_count());
EXPECT_EQ(ptr.get(), opt->get()); EXPECT_EQ(ptr.get(), opt->get());
opt.clear(); opt.reset();
EXPECT_EQ(1, ptr.use_count()); EXPECT_EQ(1, ptr.use_count());
// full->moved // full->moved
opt = std::move(ptr); opt = std::move(ptr);
......
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