THRIFT-3067 C++ cppcheck performance related warnings
Patch: Arijit Chattopadhyay <arijitnit06@gmail.com>
This closes #444
diff --git a/.travis.yml b/.travis.yml
index b49c0a3..ce9ec9b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,6 +31,7 @@
- gcc
before_install:
+ add sudo
- sh build/travis/installCXXDependencies.sh
- if [ "$ALL_DEPS" != "no" ] ; then sh build/travis/installDependencies.sh 1> /dev/null ; fi
- if [ "$ALL_DEPS" != "no" ] ; then export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/1.20/bin:$PATH ; fi
diff --git a/compiler/cpp/src/parse/t_enum.h b/compiler/cpp/src/parse/t_enum.h
index 59941e3..12b4ad8 100644
--- a/compiler/cpp/src/parse/t_enum.h
+++ b/compiler/cpp/src/parse/t_enum.h
@@ -31,13 +31,13 @@
public:
t_enum(t_program* program) : t_type(program) {}
- void set_name(const std::string& name) { name_ = name; }
+ void set_name(const std::string &name) { name_ = name; }
void append(t_enum_value* constant) { constants_.push_back(constant); }
const std::vector<t_enum_value*>& get_constants() { return constants_; }
- t_enum_value* get_constant_by_name(const std::string name) {
+ t_enum_value* get_constant_by_name(const std::string& name) {
const std::vector<t_enum_value*>& enum_values = get_constants();
std::vector<t_enum_value*>::const_iterator c_iter;
for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
diff --git a/compiler/cpp/src/parse/t_service.h b/compiler/cpp/src/parse/t_service.h
index 091403d..1f49972 100644
--- a/compiler/cpp/src/parse/t_service.h
+++ b/compiler/cpp/src/parse/t_service.h
@@ -39,7 +39,7 @@
void add_function(t_function* func) {
std::vector<t_function*>::const_iterator iter;
- for (iter = functions_.begin(); iter != functions_.end(); iter++) {
+ for (iter = functions_.begin(); iter != functions_.end(); ++iter) {
if (func->get_name() == (*iter)->get_name()) {
throw "Function " + func->get_name() + " is already defined";
}
diff --git a/contrib/fb303/TClientInfo.cpp b/contrib/fb303/TClientInfo.cpp
index 5959fb1..1fc6612 100644
--- a/contrib/fb303/TClientInfo.cpp
+++ b/contrib/fb303/TClientInfo.cpp
@@ -154,9 +154,8 @@
}
timespec start;
- double secs = 0.0;
info->getTime(&start);
- secs = (double)(now.tv_sec - start.tv_sec) + (now.tv_nsec - start.tv_nsec)*0.000000001;
+ double secs = (double)(now.tv_sec - start.tv_sec) + (now.tv_nsec - start.tv_nsec)*0.000000001;
char buf[256];
snprintf(buf, sizeof buf, "%d %s %s %.3f %llu", i, addrStr, callStr, secs,
diff --git a/contrib/fb303/cpp/FacebookBase.cpp b/contrib/fb303/cpp/FacebookBase.cpp
index 8003340..3c56975 100644
--- a/contrib/fb303/cpp/FacebookBase.cpp
+++ b/contrib/fb303/cpp/FacebookBase.cpp
@@ -98,7 +98,7 @@
// want our read/write structure to go over the wire
counters_.acquireRead();
for(ReadWriteCounterMap::iterator it = counters_.begin();
- it != counters_.end(); it++)
+ it != counters_.end(); ++it)
{
_return[it->first] = it->second.value;
}
diff --git a/contrib/fb303/cpp/ServiceTracker.cpp b/contrib/fb303/cpp/ServiceTracker.cpp
index 2914ff6..7a61b21 100644
--- a/contrib/fb303/cpp/ServiceTracker.cpp
+++ b/contrib/fb303/cpp/ServiceTracker.cpp
@@ -251,7 +251,7 @@
uint64_t count;
for (iter = checkpointServiceDuration_.begin();
iter != checkpointServiceDuration_.end();
- iter++) {
+ ++iter) {
count = iter->second.first;
handler_->setCounter(string("checkpoint_count_") + iter->first, count);
if (count == 0) {
diff --git a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
index 255d237..0e7ccd8 100644
--- a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
+++ b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
@@ -332,7 +332,7 @@
}
for (std::set<shared_ptr<Thread> >::iterator ix = newThreads.begin(); ix != newThreads.end();
- ix++) {
+ ++ix) {
shared_ptr<ThreadManager::Worker> worker
= dynamic_pointer_cast<ThreadManager::Worker, Runnable>((*ix)->runnable());
worker->state_ = ThreadManager::Worker::STARTING;
@@ -427,7 +427,7 @@
for (std::set<shared_ptr<Thread> >::iterator ix = deadWorkers_.begin();
ix != deadWorkers_.end();
- ix++) {
+ ++ix) {
idMap_.erase((*ix)->getId());
workers_.erase(*ix);
}
diff --git a/lib/cpp/src/thrift/concurrency/TimerManager.cpp b/lib/cpp/src/thrift/concurrency/TimerManager.cpp
index 60b8c85..122d26e 100644
--- a/lib/cpp/src/thrift/concurrency/TimerManager.cpp
+++ b/lib/cpp/src/thrift/concurrency/TimerManager.cpp
@@ -117,7 +117,7 @@
for (std::set<shared_ptr<Task> >::iterator ix = expiredTasks.begin();
ix != expiredTasks.end();
- ix++) {
+ ++ix) {
(*ix)->run();
}