[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
main
Abhishek Kona 12 years ago
parent a77bc3d14c
commit 0e40185a7d
  1. 17
      db/table_cache.cc

@ -12,14 +12,9 @@
namespace leveldb { namespace leveldb {
struct TableAndFile {
unique_ptr<Table> table;
};
static void DeleteEntry(const Slice& key, void* value) { static void DeleteEntry(const Slice& key, void* value) {
TableAndFile* tf = reinterpret_cast<TableAndFile*>(value); Table* table = reinterpret_cast<Table*>(value);
delete tf; delete table;
} }
static void UnrefEntry(void* arg1, void* arg2) { 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, // We do not cache error results so that if the error is transient,
// or somebody repairs the file, we recover automatically. // or somebody repairs the file, we recover automatically.
} else { } else {
TableAndFile* tf = new TableAndFile;
tf->table = std::move(table);
assert(file.get() == nullptr); assert(file.get() == nullptr);
*handle = cache_->Insert(key, tf, 1, &DeleteEntry); *handle = cache_->Insert(key, table.release(), 1, &DeleteEntry);
} }
} }
return s; return s;
@ -93,7 +86,7 @@ Iterator* TableCache::NewIterator(const ReadOptions& options,
} }
Table* table = Table* table =
reinterpret_cast<TableAndFile*>(cache_->Value(handle))->table.get(); reinterpret_cast<Table*>(cache_->Value(handle));
Iterator* result = table->NewIterator(options); Iterator* result = table->NewIterator(options);
result->RegisterCleanup(&UnrefEntry, cache_.get(), handle); result->RegisterCleanup(&UnrefEntry, cache_.get(), handle);
if (tableptr != nullptr) { if (tableptr != nullptr) {
@ -114,7 +107,7 @@ Status TableCache::Get(const ReadOptions& options,
&handle, tableIO); &handle, tableIO);
if (s.ok()) { if (s.ok()) {
Table* t = Table* t =
reinterpret_cast<TableAndFile*>(cache_->Value(handle))->table.get(); reinterpret_cast<Table*>(cache_->Value(handle));
s = t->InternalGet(options, k, arg, saver); s = t->InternalGet(options, k, arg, saver);
cache_->Release(handle); cache_->Release(handle);
} }

Loading…
Cancel
Save