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