From a094f3b3b5568f4af37c081c7cea4b77e747b2e3 Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Thu, 26 Dec 2013 16:25:45 -0800 Subject: [PATCH] TableCache.FindTable() to avoid the mem copy of file number Summary: I'm not sure what's the purpose of encoding file number to a new buffer for looking up the table cache. It seems to be unnecessary to me. With this patch, we point the lookup key to the address of the int64 of the file number. Test Plan: make all check Reviewers: dhruba, haobo, igor, kailiu Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D14811 --- db/table_cache.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/table_cache.cc b/db/table_cache.cc index e18c20c99..20eb68e4b 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -29,6 +29,11 @@ static void UnrefEntry(void* arg1, void* arg2) { cache->Release(h); } +static Slice GetSliceForFileNumber(uint64_t file_number) { + return Slice(reinterpret_cast(&file_number), + sizeof(file_number)); +} + TableCache::TableCache(const std::string& dbname, const Options* options, const EnvOptions& storage_options, @@ -50,9 +55,7 @@ Status TableCache::FindTable(const EnvOptions& toptions, Cache::Handle** handle, bool* table_io, const bool no_io) { Status s; - char buf[sizeof(file_number)]; - EncodeFixed64(buf, file_number); - Slice key(buf, sizeof(buf)); + Slice key = GetSliceForFileNumber(file_number); *handle = cache_->Lookup(key); if (*handle == nullptr) { if (no_io) { // Dont do IO and return a not-found status @@ -165,9 +168,7 @@ bool TableCache::PrefixMayMatch(const ReadOptions& options, } void TableCache::Evict(uint64_t file_number) { - char buf[sizeof(file_number)]; - EncodeFixed64(buf, file_number); - cache_->Erase(Slice(buf, sizeof(buf))); + cache_->Erase(GetSliceForFileNumber(file_number)); } } // namespace rocksdb