From 0e40185a7d378bdfd0cbe11a7eb6d02c6239371f Mon Sep 17 00:00:00 2001 From: Abhishek Kona Date: Fri, 5 Apr 2013 11:26:46 -0700 Subject: [PATCH] [Rocksdb] Remove useless struct TableAndFile Summary: TableAndFile was a struct used earlier to delete the file as we did not have std::unique_ptr in the codebase. With Chip introducing C++11 hotness like std::unique_ptr we can do away with the struct. Test Plan: make all check Reviewers: haobo, heyongqiang Reviewed By: heyongqiang CC: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D9975 --- db/table_cache.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/db/table_cache.cc b/db/table_cache.cc index 163795e9d..0894d5bab 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -12,14 +12,9 @@ namespace leveldb { -struct TableAndFile { - unique_ptr table; -}; - - static void DeleteEntry(const Slice& key, void* value) { - TableAndFile* tf = reinterpret_cast(value); - delete tf; + Table* table = reinterpret_cast(value); + delete table; } static void UnrefEntry(void* arg1, void* arg2) { @@ -68,10 +63,8 @@ Status TableCache::FindTable(const EnvOptions& toptions, // We do not cache error results so that if the error is transient, // or somebody repairs the file, we recover automatically. } else { - TableAndFile* tf = new TableAndFile; - tf->table = std::move(table); assert(file.get() == nullptr); - *handle = cache_->Insert(key, tf, 1, &DeleteEntry); + *handle = cache_->Insert(key, table.release(), 1, &DeleteEntry); } } return s; @@ -93,7 +86,7 @@ Iterator* TableCache::NewIterator(const ReadOptions& options, } Table* table = - reinterpret_cast(cache_->Value(handle))->table.get(); + reinterpret_cast(cache_->Value(handle)); Iterator* result = table->NewIterator(options); result->RegisterCleanup(&UnrefEntry, cache_.get(), handle); if (tableptr != nullptr) { @@ -114,7 +107,7 @@ Status TableCache::Get(const ReadOptions& options, &handle, tableIO); if (s.ok()) { Table* t = - reinterpret_cast(cache_->Value(handle))->table.get(); + reinterpret_cast(cache_->Value(handle)); s = t->InternalGet(options, k, arg, saver); cache_->Release(handle); }