[RocksDB] Replace iterator based loop with range based loop for stl containers

Summary:
As title.
Code is shorter and cleaner
See https://our.dev.facebook.com/intern/tasks/?t=2233981

Test Plan: make check

Reviewers: dhruba, heyongqiang

Reviewed By: dhruba

CC: leveldb, zshao

Differential Revision: https://reviews.facebook.net/D9789
This commit is contained in:
Haobo Xu 2013-03-28 18:01:06 -07:00
parent d815082159
commit 6763110867

View File

@ -443,24 +443,21 @@ void DBImpl::PurgeObsoleteWALFiles() {
int64_t currentTime; int64_t currentTime;
const Status status = env_->GetCurrentTime(&currentTime); const Status status = env_->GetCurrentTime(&currentTime);
assert(status.ok()); assert(status.ok());
for (std::vector<std::string>::iterator it = WALFiles.begin(); for (const auto& f : WALFiles) {
it != WALFiles.end(); uint64_t fileMTime;
++it) { const std::string filePath = archivalDir + "/" + f;
const Status s = env_->GetFileModificationTime(filePath, &fileMTime);
uint64_t fileMTime; if (s.ok()) {
const std::string filePath = archivalDir + "/" + *it; if (status.ok() &&
const Status s = env_->GetFileModificationTime(filePath, &fileMTime); (currentTime - fileMTime > options_.WAL_ttl_seconds)) {
if (s.ok()) { Status delStatus = env_->DeleteFile(filePath);
if (status.ok() && if (!delStatus.ok()) {
(currentTime - fileMTime > options_.WAL_ttl_seconds)) { Log(options_.info_log,
Status delStatus = env_->DeleteFile(filePath); "Failed Deleting a WAL file Error : i%s",
if (!delStatus.ok()) { delStatus.ToString().c_str());
Log(options_.info_log, }
"Failed Deleting a WAL file Error : i%s",
delStatus.ToString().c_str());
} }
} } // Ignore errors.
} // Ignore errors.
} }
} }
} }
@ -1051,12 +1048,10 @@ Status DBImpl::ListAllWALFiles(const std::string& path,
if (!status.ok()) { if (!status.ok()) {
return status; return status;
} }
for(std::vector<std::string>::iterator it = allFiles.begin(); for (const auto& f : allFiles) {
it != allFiles.end();
++it) {
uint64_t number; uint64_t number;
FileType type; FileType type;
if (ParseFileName(*it, &number, &type) && type == kLogFile){ if (ParseFileName(f, &number, &type) && type == kLogFile){
logFiles->push_back(LogFile(number, logType)); logFiles->push_back(LogFile(number, logType));
} }
} }
@ -1366,10 +1361,7 @@ void DBImpl::AllocateCompactionOutputFileNumbers(CompactionState* compact) {
// Frees up unused file number. // Frees up unused file number.
void DBImpl::ReleaseCompactionUnusedFileNumbers(CompactionState* compact) { void DBImpl::ReleaseCompactionUnusedFileNumbers(CompactionState* compact) {
mutex_.AssertHeld(); mutex_.AssertHeld();
for (std::list<uint64_t>::iterator it = for (const auto file_number : compact->allocated_file_numbers) {
compact->allocated_file_numbers.begin();
it != compact->allocated_file_numbers.end(); ++it) {
uint64_t file_number = *it;
pending_outputs_.erase(file_number); pending_outputs_.erase(file_number);
// Log(options_.info_log, "XXX releasing unused file num %d", file_number); // Log(options_.info_log, "XXX releasing unused file num %d", file_number);
} }
@ -1513,13 +1505,13 @@ Status DBImpl::InstallCompactionResults(CompactionState* compact) {
inline SequenceNumber DBImpl::findEarliestVisibleSnapshot( inline SequenceNumber DBImpl::findEarliestVisibleSnapshot(
SequenceNumber in, std::vector<SequenceNumber>& snapshots) { SequenceNumber in, std::vector<SequenceNumber>& snapshots) {
SequenceNumber prev __attribute__((unused)) = 0; SequenceNumber prev __attribute__((unused)) = 0;
for (std::vector<SequenceNumber>::iterator it = snapshots.begin(); for (const auto cur : snapshots) {
it < snapshots.end(); it++) { assert(prev <= cur);
assert (prev <= *it); if (cur >= in) {
if (*it >= in) { return cur;
return *it;
} }
assert(prev = *it); // assignment prev = cur; // assignment
assert(prev);
} }
Log(options_.info_log, Log(options_.info_log,
"Looking for seqid %ld but maxseqid is %ld", in, "Looking for seqid %ld but maxseqid is %ld", in,