Skip to content

Commit

Permalink
Eliminate use of 'using namespace std'. Also remove a number of ADL r…
Browse files Browse the repository at this point in the history
…eferences to std functions.

Summary: Reduce use of argument-dependent name lookup in RocksDB.

Test Plan: 'make check' passed.

Reviewers: andrewkr

Reviewed By: andrewkr

Subscribers: leveldb, andrewkr, dhruba

Differential Revision: https://reviews.facebook.net/D58203
  • Loading branch information
aorenste committed May 20, 2016
1 parent 26adaad commit 2073cf3
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 444 deletions.
7 changes: 3 additions & 4 deletions db/auto_roll_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "db/auto_roll_logger.h"
#include "util/mutexlock.h"

using namespace std;

namespace rocksdb {

// -- AutoRollLogger
Expand Down Expand Up @@ -47,7 +45,8 @@ void AutoRollLogger::RollLogFile() {
env_->RenameFile(log_fname_, old_fname);
}

string AutoRollLogger::ValistToString(const char* format, va_list args) const {
std::string AutoRollLogger::ValistToString(const char* format,
va_list args) const {
// Any log messages longer than 1024 will get truncated.
// The user is responsible for chopping longer messages into multi line log
static const int MAXBUFFERSIZE = 1024;
Expand Down Expand Up @@ -112,7 +111,7 @@ void AutoRollLogger::LogHeader(const char* format, va_list args) {
// strings
va_list tmp;
va_copy(tmp, args);
string data = ValistToString(format, tmp);
std::string data = ValistToString(format, tmp);
va_end(tmp);

MutexLock l(&mutex_);
Expand Down
52 changes: 25 additions & 27 deletions db/auto_roll_logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <sys/stat.h>
#include <errno.h>

using namespace std;

namespace rocksdb {

class AutoRollLoggerTest : public testing::Test {
Expand All @@ -40,23 +38,22 @@ class AutoRollLoggerTest : public testing::Test {
Env::Default()->CreateDir(kTestDir);
}

void RollLogFileBySizeTest(AutoRollLogger* logger,
size_t log_max_size,
const string& log_message);
uint64_t RollLogFileByTimeTest(AutoRollLogger* logger,
size_t time,
const string& log_message);
void RollLogFileBySizeTest(AutoRollLogger* logger, size_t log_max_size,
const std::string& log_message);
uint64_t RollLogFileByTimeTest(AutoRollLogger* logger, size_t time,
const std::string& log_message);

static const string kSampleMessage;
static const string kTestDir;
static const string kLogFile;
static const std::string kSampleMessage;
static const std::string kTestDir;
static const std::string kLogFile;
static Env* env;
};

const string AutoRollLoggerTest::kSampleMessage(
const std::string AutoRollLoggerTest::kSampleMessage(
"this is the message to be written to the log file!!");
const string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test");
const string AutoRollLoggerTest::kLogFile(test::TmpDir() + "/db_log_test/LOG");
const std::string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test");
const std::string AutoRollLoggerTest::kLogFile(test::TmpDir() +
"/db_log_test/LOG");
Env* AutoRollLoggerTest::env = Env::Default();

// In this test we only want to Log some simple log message with
Expand Down Expand Up @@ -86,7 +83,7 @@ void GetFileCreateTime(const std::string& fname, uint64_t* file_ctime) {

void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger,
size_t log_max_size,
const string& log_message) {
const std::string& log_message) {
logger->SetInfoLogLevel(InfoLogLevel::INFO_LEVEL);
// measure the size of each message, which is supposed
// to be equal or greater than log_message.size()
Expand All @@ -111,7 +108,7 @@ void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger,
}

uint64_t AutoRollLoggerTest::RollLogFileByTimeTest(
AutoRollLogger* logger, size_t time, const string& log_message) {
AutoRollLogger* logger, size_t time, const std::string& log_message) {
uint64_t expected_create_time;
uint64_t actual_create_time;
uint64_t total_log_size;
Expand Down Expand Up @@ -361,13 +358,13 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) {

// Test the logger Header function for roll over logs
// We expect the new logs creates as roll over to carry the headers specified
static std::vector<string> GetOldFileNames(const string& path) {
std::vector<string> ret;
static std::vector<std::string> GetOldFileNames(const std::string& path) {
std::vector<std::string> ret;

const string dirname = path.substr(/*start=*/ 0, path.find_last_of("/"));
const string fname = path.substr(path.find_last_of("/") + 1);
const std::string dirname = path.substr(/*start=*/0, path.find_last_of("/"));
const std::string fname = path.substr(path.find_last_of("/") + 1);

std::vector<string> children;
std::vector<std::string> children;
Env::Default()->GetChildren(dirname, &children);

// We know that the old log files are named [path]<something>
Expand All @@ -382,12 +379,13 @@ static std::vector<string> GetOldFileNames(const string& path) {
}

// Return the number of lines where a given pattern was found in the file
static size_t GetLinesCount(const string& fname, const string& pattern) {
stringstream ssbuf;
string line;
static size_t GetLinesCount(const std::string& fname,
const std::string& pattern) {
std::stringstream ssbuf;
std::string line;
size_t count = 0;

ifstream inFile(fname.c_str());
std::ifstream inFile(fname.c_str());
ssbuf << inFile.rdbuf();

while (getline(ssbuf, line)) {
Expand Down Expand Up @@ -426,7 +424,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
}
}

const string newfname = logger.TEST_log_fname();
const std::string newfname = logger.TEST_log_fname();

// Log enough data to cause a roll over
int i = 0;
Expand Down Expand Up @@ -466,7 +464,7 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) {
[](char ch) { return ch == '/'; }, '\\');
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir;
#else
string deleteCmd = "rm -rf " + kTestDir;
std::string deleteCmd = "rm -rf " + kTestDir;
#endif
ASSERT_EQ(system(deleteCmd.c_str()), 0);
options.max_log_file_size = 100 * 1024 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion db/column_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ TEST_F(ColumnFamilyTest, AddDrop) {

std::vector<std::string> families;
ASSERT_OK(DB::ListColumnFamilies(db_options_, dbname_, &families));
sort(families.begin(), families.end());
std::sort(families.begin(), families.end());
ASSERT_TRUE(families ==
std::vector<std::string>({"default", "four", "three"}));
}
Expand Down
8 changes: 5 additions & 3 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,11 @@ void DBImpl::PurgeObsoleteFiles(const JobContext& state) {

// dedup state.candidate_files so we don't try to delete the same
// file twice
sort(candidate_files.begin(), candidate_files.end(), CompareCandidateFile);
candidate_files.erase(unique(candidate_files.begin(), candidate_files.end()),
candidate_files.end());
std::sort(candidate_files.begin(), candidate_files.end(),
CompareCandidateFile);
candidate_files.erase(
std::unique(candidate_files.begin(), candidate_files.end()),
candidate_files.end());

std::vector<std::string> old_info_log_files;
InfoLogPrefix info_log_prefix(!db_options_.db_log_dir.empty(), dbname_);
Expand Down
2 changes: 1 addition & 1 deletion db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ TEST_F(DBTest, GroupCommitTest) {
for (int i = 0; i < kGCNumThreads * kGCNumKeys; ++i) {
expected_db.push_back(ToString(i));
}
sort(expected_db.begin(), expected_db.end());
std::sort(expected_db.begin(), expected_db.end());

Iterator* itr = db_->NewIterator(ReadOptions());
itr->SeekToFirst();
Expand Down
11 changes: 5 additions & 6 deletions db/transaction_log_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define __STDC_FORMAT_MACROS
#endif

#include <inttypes.h>
#include "db/transaction_log_impl.h"
#include <inttypes.h>
#include "db/write_batch_internal.h"
#include "util/file_reader_writer.h"

Expand Down Expand Up @@ -250,7 +250,7 @@ void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) {
// currentBatchSeq_ can only change here
assert(currentLastSeq_ <= versions_->LastSequence());

currentBatch_ = move(batch);
currentBatch_ = std::move(batch);
isValid_ = true;
currentStatus_ = Status::OK();
}
Expand All @@ -262,10 +262,9 @@ Status TransactionLogIteratorImpl::OpenLogReader(const LogFile* logFile) {
return s;
}
assert(file);
currentLogReader_.reset(new log::Reader(options_->info_log,
std::move(file), &reporter_,
read_options_.verify_checksums_, 0,
logFile->LogNumber()));
currentLogReader_.reset(new log::Reader(
options_->info_log, std::move(file), &reporter_,
read_options_.verify_checksums_, 0, logFile->LogNumber()));
return Status::OK();
}
} // namespace rocksdb
Expand Down
10 changes: 5 additions & 5 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,11 @@ void VersionStorageInfo::GenerateLevel0NonOverlapping() {
std::vector<FdWithKeyRange> level0_sorted_file(
level_files_brief_[0].files,
level_files_brief_[0].files + level_files_brief_[0].num_files);
sort(level0_sorted_file.begin(), level0_sorted_file.end(),
[this](const FdWithKeyRange & f1, const FdWithKeyRange & f2)->bool {
return (internal_comparator_->Compare(f1.smallest_key, f2.smallest_key) <
0);
});
std::sort(level0_sorted_file.begin(), level0_sorted_file.end(),
[this](const FdWithKeyRange& f1, const FdWithKeyRange& f2) -> bool {
return (internal_comparator_->Compare(f1.smallest_key,
f2.smallest_key) < 0);
});

for (size_t i = 1; i < level0_sorted_file.size(); ++i) {
FdWithKeyRange& f = level0_sorted_file[i];
Expand Down
13 changes: 5 additions & 8 deletions port/win/xpress_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ char* Decompress(const char* input_data, size_t input_length,

if (!success) {
#ifdef _DEBUG
std::cerr <<
"XPRESS: Failed to create Decompressor LastError " <<
GetLastError() << std::endl;
std::cerr << "XPRESS: Failed to create Decompressor LastError "
<< GetLastError() << std::endl;
#endif
return nullptr;
}
Expand All @@ -215,9 +214,9 @@ char* Decompress(const char* input_data, size_t input_length,

if (lastError != ERROR_INSUFFICIENT_BUFFER) {
#ifdef _DEBUG
std::cerr <<
"XPRESS: Failed to estimate decompressed buffer size LastError " <<
lastError << std::endl;
std::cerr
<< "XPRESS: Failed to estimate decompressed buffer size LastError "
<< lastError << std::endl;
#endif
return nullptr;
}
Expand Down Expand Up @@ -266,5 +265,3 @@ char* Decompress(const char* input_data, size_t input_length,
}

#endif


5 changes: 3 additions & 2 deletions tools/db_stress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2152,8 +2152,9 @@ class StressTest {
// this is a reopen. just assert that existing column_family_names are
// equivalent to what we remember
auto sorted_cfn = column_family_names_;
sort(sorted_cfn.begin(), sorted_cfn.end());
sort(existing_column_families.begin(), existing_column_families.end());
std::sort(sorted_cfn.begin(), sorted_cfn.end());
std::sort(existing_column_families.begin(),
existing_column_families.end());
if (sorted_cfn != existing_column_families) {
fprintf(stderr,
"Expected column families differ from the existing:\n");
Expand Down
Loading

0 comments on commit 2073cf3

Please sign in to comment.