From: "Martin Ettl" <ettl.martin@gmx.de>
To: ceph-devel@lists.sourceforge.net
Subject: [cppcheck] suggested a few performance improvements
Date: Mon, 22 Mar 2010 21:35:02 +0100 [thread overview]
Message-ID: <20100322203502.295370@gmx.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]
Hello,
i have checked the current git head with cppcheck ( a static code analysis tool, http://sourceforge.net/projects/cppcheck/). It is an allready very powerfull tool that makes some suggestions, how to improve performance of the code.
Here is a snipped of the scan:
....
[./src/mds/MDSMap.h:236]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/mds/MDSMap.h:256]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/mds/MDSMap.h:263]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/mds/MDSMap.h:280]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/mds/MDSMap.h:291]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/include/LogEntry.h:100]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/ceph.cc:317]: (possible style) Pre-Incrementing variable 'p' is preferred to Post-Incrementing
[./src/mds/MDSMap.h:247]: (possible style) Use failed.empty() instead of failed.size() to guarantee fast code.
....
Please refer the attached patch that chanes a few of this suggestions.
What do you think about this? Does it boost the performance?
Best regards
Ettl Martin
--
GMX.at - Österreichs FreeMail-Dienst mit über 2 Mio Mitgliedern
E-Mail, SMS & mehr! Kostenlos: http://portal.gmx.net/de/go/atfreemail
[-- Attachment #2: Performance_improvements_cppcheck.patch --]
[-- Type: text/x-patch, Size: 3246 bytes --]
diff --git a/src/mds/Capability.h b/src/mds/Capability.h
index 6afbe98..571e50e 100644
--- a/src/mds/Capability.h
+++ b/src/mds/Capability.h
@@ -183,7 +183,7 @@ public:
}
void _calc_issued() {
_issued = _pending;
- for (list<revoke_info>::iterator p = _revokes.begin(); p != _revokes.end(); p++)
+ for (list<revoke_info>::iterator p = _revokes.begin(); p != _revokes.end(); ++p)
_issued |= p->before;
}
void confirm_receipt(ceph_seq_t seq, unsigned caps) {
diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h
index 533ec4f..2def085 100644
--- a/src/mds/MDSMap.h
+++ b/src/mds/MDSMap.h
@@ -220,7 +220,7 @@ public:
unsigned n = 0;
for (map<__u64,mds_info_t>::const_iterator p = mds_info.begin();
p != mds_info.end();
- p++)
+ ++p)
if (p->second.state == state) ++n;
return n;
}
@@ -234,7 +234,7 @@ public:
void get_up_mds_set(set<int>& s) {
for (map<int32_t,__u64>::const_iterator p = up.begin();
p != up.end();
- p++)
+ ++p)
s.insert(p->first);
}
void get_active_mds_set(set<int>& s) {
@@ -244,7 +244,7 @@ public:
s = failed;
}
int get_failed() {
- if (failed.size()) return *failed.begin();
+ if (!failed.empty()) return *failed.begin();
return -1;
}
void get_stopped_mds_set(set<int>& s) {
@@ -254,14 +254,14 @@ public:
s = failed;
for (map<__u64,mds_info_t>::const_iterator p = mds_info.begin();
p != mds_info.end();
- p++)
+ ++p)
if (p->second.state >= STATE_REPLAY && p->second.state <= STATE_STOPPING)
s.insert(p->second.rank);
}
void get_mds_set(set<int>& s, int state) {
for (map<__u64,mds_info_t>::const_iterator p = mds_info.begin();
p != mds_info.end();
- p++)
+ ++p)
if (p->second.state == state)
s.insert(p->second.rank);
}
@@ -278,7 +278,7 @@ public:
__u64 find_standby_for(int mds, string& name) {
for (map<__u64,mds_info_t>::const_iterator p = mds_info.begin();
p != mds_info.end();
- p++) {
+ ++p) {
if (p->second.rank == -1 &&
(p->second.standby_for_rank == mds ||
p->second.standby_for_name == name) &&
@@ -289,7 +289,7 @@ public:
}
for (map<__u64,mds_info_t>::const_iterator p = mds_info.begin();
p != mds_info.end();
- p++) {
+ ++p) {
if (p->second.rank == -1 &&
p->second.standby_for_rank < 0 &&
p->second.standby_for_name.length() == 0 &&
diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h
index ca8b9ae..465defc 100644
--- a/src/mds/mdstypes.h
+++ b/src/mds/mdstypes.h
@@ -385,7 +385,7 @@ struct inode_t {
__u64 max = 0;
for (map<client_t,byte_range_t>::const_iterator p = client_ranges.begin();
p != client_ranges.end();
- p++)
+ ++p)
if (p->second.last > max)
max = p->second.last;
return max;
@@ -396,7 +396,7 @@ struct inode_t {
} else {
for (map<client_t,byte_range_t>::iterator p = client_ranges.begin();
p != client_ranges.end();
- p++)
+ ++p)
p->second.last = new_max;
}
}
@@ -1331,7 +1331,7 @@ protected:
}
for (multimap<__u64,Context*>::iterator p = waiting.lower_bound(min);
p != waiting.end();
- p++) {
+ ++p) {
if (p->first & mask) return true;
if (p->first > mask) return false;
}
[-- Attachment #3: Type: text/plain, Size: 345 bytes --]
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
[-- Attachment #4: Type: text/plain, Size: 161 bytes --]
_______________________________________________
Ceph-devel mailing list
Ceph-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ceph-devel
next reply other threads:[~2010-03-22 20:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-22 20:35 Martin Ettl [this message]
2010-03-22 20:49 ` [cppcheck] suggested a few performance improvements Sage Weil
2010-03-24 20:08 ` Martin Ettl
2010-03-25 18:57 ` Sage Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100322203502.295370@gmx.net \
--to=ettl.martin@gmx.de \
--cc=ceph-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.