Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use more common (and readable) names for branch prediction hints

  • Loading branch information...
commit e2778cdf78239e136eaa36680869608441fc9934 1 parent a83ddcd
Mathias Stearn RedBeard0531 authored
2  bson/bson-inl.h
@@ -172,7 +172,7 @@ namespace mongo {
172 172 }
173 173
174 174 inline BSONObj BSONElement::embeddedObjectUserCheck() const {
175   - MONGOIF ( isABSONObj() )
  175 + if ( MONGO_likely(isABSONObj()) )
176 176 return BSONObj(value());
177 177 stringstream ss;
178 178 ss << "invalid parameter: expected an object (" << fieldName() << ")";
2  bson/bsonobjiterator.h
@@ -37,7 +37,7 @@ namespace mongo {
37 37 */
38 38 BSONObjIterator(const BSONObj& jso) {
39 39 int sz = jso.objsize();
40   - MONGO_IF ( sz == 0 ) {
  40 + if ( MONGO_unlikely(sz == 0) ) {
41 41 _pos = _theend = 0;
42 42 return;
43 43 }
12 bson/inline_decls.h
@@ -37,11 +37,11 @@ namespace mongo {
37 37
38 38 #if !defined(__GNUC__)
39 39
40   -// branch prediction. indicate we expect to enter the if statement body
41   -# define MONGOIF(x) if( (x) )
  40 +// branch prediction. indicate we expect to be true
  41 +# define MONGO_likely(x) ((bool)(x))
42 42
43   -// branch prediction. indicate we expect to not enter the if statement body
44   -# define MONGO_IF(x) if( (x) )
  43 +// branch prediction. indicate we expect to be false
  44 +# define MONGO_unlikely(x) ((bool)(x))
45 45
46 46 # if defined(_WIN32)
47 47 // prefetch data from memory
@@ -56,8 +56,8 @@ namespace mongo {
56 56
57 57 #else
58 58
59   -# define MONGOIF(x) if( __builtin_expect((x), 1) )
60   -# define MONGO_IF(x) if( __builtin_expect((x), 0) )
  59 +# define MONGO_likely(x) ( __builtin_expect((bool)(x), 1) )
  60 +# define MONGO_unlikely(x) ( __builtin_expect((bool)(x), 0) )
61 61
62 62 inline void prefetch(void *p) {
63 63 __builtin_prefetch(p);
4 db/dur_preplogbuffer.cpp
@@ -60,7 +60,7 @@ namespace mongo {
60 60 size_t ofs = 1;
61 61 MongoMMF *mmf = findMMF_inlock(i->start(), /*out*/ofs);
62 62
63   - _IF( !mmf->willNeedRemap() ) {
  63 + if( unlikely(!mmf->willNeedRemap()) ) {
64 64 // tag this mmf as needed a remap of its private view later.
65 65 // usually it will already be dirty/already set, so we do the if above first
66 66 // to avoid possibility of cpu cache line contention
@@ -97,7 +97,7 @@ namespace mongo {
97 97 #endif
98 98 bb.appendBuf(i->start(), e.len);
99 99
100   - _IF (e.len != (unsigned)i->length()) {
  100 + if (unlikely(e.len != (unsigned)i->length())) {
101 101 log() << "journal info splitting prepBasicWrite at boundary" << endl;
102 102
103 103 // This only happens if we write to the last byte in a file and
2  db/ops/query.cpp
@@ -101,7 +101,7 @@ namespace mongo {
101 101 int start = 0;
102 102 int n = 0;
103 103
104   - _IF ( !cc ) {
  104 + if ( unlikely(!cc) ) {
105 105 log() << "getMore: cursorid not found " << ns << " " << cursorid << endl;
106 106 cursorid = 0;
107 107 resultFlags = ResultFlag_CursorNotFound;
8 server.h
@@ -13,9 +13,9 @@
13 13
14 14 /* Note: do not clutter code with these -- ONLY use in hot spots / significant loops. */
15 15
16   -// branch prediction. indicate we expect to enter the if statement body
17   -#define IF MONGOIF
  16 +// branch prediction. indicate we expect to be true
  17 +#define likely MONGO_likely
18 18
19   -// branch prediction. indicate we expect to not enter the if statement body
20   -#define _IF MONGO_IF
  19 +// branch prediction. indicate we expect to be false
  20 +#define unlikely MONGO_unlikely
21 21
2  util/alignedbuilder.h
@@ -101,7 +101,7 @@ namespace mongo {
101 101 inline char* grow(unsigned by) {
102 102 unsigned oldlen = _len;
103 103 _len += by;
104   - MONGO_IF ( _len > _p._size ) {
  104 + if (MONGO_unlikely( _len > _p._size )) {
105 105 growReallocate(oldlen);
106 106 }
107 107 return _p._data + oldlen;
2  util/concurrency/rwlock.h
@@ -175,7 +175,7 @@ namespace mongo {
175 175 pthread_rwlock_t _lock;
176 176 const int _lowPriorityWaitMS;
177 177 static void check( int x ) {
178   - MONGOIF( x == 0 )
  178 + if( likely(x == 0) )
179 179 return;
180 180 log() << "pthread rwlock failed: " << x << endl;
181 181 assert( x == 0 );
2  util/log.h
@@ -345,7 +345,7 @@ namespace mongo {
345 345 return Logstream::get().prolog();
346 346 }
347 347
348   -#define MONGO_LOG(level) MONGO_IF ( logLevel >= (level) ) log( level )
  348 +#define MONGO_LOG(level) if ( MONGO_unlikely(logLevel >= (level)) ) log( level )
349 349 #define LOG MONGO_LOG
350 350
351 351 inline Nullstream& log( LogLevel l ) {

0 comments on commit e2778cd

Please sign in to comment.
Something went wrong with that request. Please try again.