summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/isself.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-05-28 14:22:27 -0400
committerBenety Goh <benety@mongodb.com>2014-05-29 08:46:18 -0400
commitda2701673900d4a0e70aca04fb9a34f424469601 (patch)
tree4e7a9310df677f2a458026b463d634d3f89a9ac3 /src/mongo/db/commands/isself.cpp
parent8f4148960e4107beb3314d7cd3214066f82c1d99 (diff)
downloadmongo-da2701673900d4a0e70aca04fb9a34f424469601.tar.gz
SERVER-11776 move port check outside loop
Diffstat (limited to 'src/mongo/db/commands/isself.cpp')
-rw-r--r--src/mongo/db/commands/isself.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/mongo/db/commands/isself.cpp b/src/mongo/db/commands/isself.cpp
index 543d512af37..c183c19c289 100644
--- a/src/mongo/db/commands/isself.cpp
+++ b/src/mongo/db/commands/isself.cpp
@@ -221,24 +221,27 @@ namespace mongo {
#if !defined(_WIN32) && !defined(__sunos__)
// on linux and os x we can do a quick check for an ip match
- const vector<string> myaddrs = getMyAddrs();
- const vector<string> addrs = getAllIPs(_host);
-
- for (vector<string>::const_iterator i=myaddrs.begin(), iend=myaddrs.end(); i!=iend; ++i) {
- for (vector<string>::const_iterator j=addrs.begin(), jend=addrs.end(); j!=jend; ++j) {
- string a = *i;
- string b = *j;
-
- // check if the ports match as well
- if ( (p == serverGlobalParams.port) &&
- (a == b || ( str::startsWith( a , "127." ) &&
- str::startsWith( b , "127." ) )) // 127. is all loopback
- ) {
-
- // add to cache
- scoped_lock lk( isSelfCommand._cacheLock );
- isSelfCommand._cache[host] = true;
- return true;
+ // no need for ip match if the ports do not match
+ if (p == serverGlobalParams.port) {
+ const vector<string> myaddrs = getMyAddrs();
+ const vector<string> addrs = getAllIPs(_host);
+
+ for (vector<string>::const_iterator i=myaddrs.begin(), iend=myaddrs.end();
+ i!=iend; ++i) {
+ for (vector<string>::const_iterator j=addrs.begin(), jend=addrs.end();
+ j!=jend; ++j) {
+ string a = *i;
+ string b = *j;
+
+ if ( a == b || ( str::startsWith( a , "127." ) &&
+ str::startsWith( b , "127." ) ) // 127. is all loopback
+ ) {
+
+ // add to cache
+ scoped_lock lk( isSelfCommand._cacheLock );
+ isSelfCommand._cache[host] = true;
+ return true;
+ }
}
}
}