Skip to content
Browse files

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

  • Loading branch information...
1 parent a83ddcd commit e2778cdf78239e136eaa36680869608441fc9934 @RedBeard0531 RedBeard0531 committed Aug 2, 2011
Showing with 18 additions and 18 deletions.
  1. +1 −1 bson/bson-inl.h
  2. +1 −1 bson/bsonobjiterator.h
  3. +6 −6 bson/inline_decls.h
  4. +2 −2 db/dur_preplogbuffer.cpp
  5. +1 −1 db/ops/query.cpp
  6. +4 −4 server.h
  7. +1 −1 util/alignedbuilder.h
  8. +1 −1 util/concurrency/rwlock.h
  9. +1 −1 util/log.h
View
2 bson/bson-inl.h
@@ -172,7 +172,7 @@ namespace mongo {
}
inline BSONObj BSONElement::embeddedObjectUserCheck() const {
- MONGOIF ( isABSONObj() )
+ if ( MONGO_likely(isABSONObj()) )
return BSONObj(value());
stringstream ss;
ss << "invalid parameter: expected an object (" << fieldName() << ")";
View
2 bson/bsonobjiterator.h
@@ -37,7 +37,7 @@ namespace mongo {
*/
BSONObjIterator(const BSONObj& jso) {
int sz = jso.objsize();
- MONGO_IF ( sz == 0 ) {
+ if ( MONGO_unlikely(sz == 0) ) {
_pos = _theend = 0;
return;
}
View
12 bson/inline_decls.h
@@ -37,11 +37,11 @@ namespace mongo {
#if !defined(__GNUC__)
-// branch prediction. indicate we expect to enter the if statement body
-# define MONGOIF(x) if( (x) )
+// branch prediction. indicate we expect to be true
+# define MONGO_likely(x) ((bool)(x))
-// branch prediction. indicate we expect to not enter the if statement body
-# define MONGO_IF(x) if( (x) )
+// branch prediction. indicate we expect to be false
+# define MONGO_unlikely(x) ((bool)(x))
# if defined(_WIN32)
// prefetch data from memory
@@ -56,8 +56,8 @@ namespace mongo {
#else
-# define MONGOIF(x) if( __builtin_expect((x), 1) )
-# define MONGO_IF(x) if( __builtin_expect((x), 0) )
+# define MONGO_likely(x) ( __builtin_expect((bool)(x), 1) )
+# define MONGO_unlikely(x) ( __builtin_expect((bool)(x), 0) )
inline void prefetch(void *p) {
__builtin_prefetch(p);
View
4 db/dur_preplogbuffer.cpp
@@ -60,7 +60,7 @@ namespace mongo {
size_t ofs = 1;
MongoMMF *mmf = findMMF_inlock(i->start(), /*out*/ofs);
- _IF( !mmf->willNeedRemap() ) {
+ if( unlikely(!mmf->willNeedRemap()) ) {
// tag this mmf as needed a remap of its private view later.
// usually it will already be dirty/already set, so we do the if above first
// to avoid possibility of cpu cache line contention
@@ -97,7 +97,7 @@ namespace mongo {
#endif
bb.appendBuf(i->start(), e.len);
- _IF (e.len != (unsigned)i->length()) {
+ if (unlikely(e.len != (unsigned)i->length())) {
log() << "journal info splitting prepBasicWrite at boundary" << endl;
// This only happens if we write to the last byte in a file and
View
2 db/ops/query.cpp
@@ -101,7 +101,7 @@ namespace mongo {
int start = 0;
int n = 0;
- _IF ( !cc ) {
+ if ( unlikely(!cc) ) {
log() << "getMore: cursorid not found " << ns << " " << cursorid << endl;
cursorid = 0;
resultFlags = ResultFlag_CursorNotFound;
View
8 server.h
@@ -13,9 +13,9 @@
/* Note: do not clutter code with these -- ONLY use in hot spots / significant loops. */
-// branch prediction. indicate we expect to enter the if statement body
-#define IF MONGOIF
+// branch prediction. indicate we expect to be true
+#define likely MONGO_likely
-// branch prediction. indicate we expect to not enter the if statement body
-#define _IF MONGO_IF
+// branch prediction. indicate we expect to be false
+#define unlikely MONGO_unlikely
View
2 util/alignedbuilder.h
@@ -101,7 +101,7 @@ namespace mongo {
inline char* grow(unsigned by) {
unsigned oldlen = _len;
_len += by;
- MONGO_IF ( _len > _p._size ) {
+ if (MONGO_unlikely( _len > _p._size )) {
growReallocate(oldlen);
}
return _p._data + oldlen;
View
2 util/concurrency/rwlock.h
@@ -175,7 +175,7 @@ namespace mongo {
pthread_rwlock_t _lock;
const int _lowPriorityWaitMS;
static void check( int x ) {
- MONGOIF( x == 0 )
+ if( likely(x == 0) )
return;
log() << "pthread rwlock failed: " << x << endl;
assert( x == 0 );
View
2 util/log.h
@@ -345,7 +345,7 @@ namespace mongo {
return Logstream::get().prolog();
}
-#define MONGO_LOG(level) MONGO_IF ( logLevel >= (level) ) log( level )
+#define MONGO_LOG(level) if ( MONGO_unlikely(logLevel >= (level)) ) log( level )
#define LOG MONGO_LOG
inline Nullstream& log( LogLevel l ) {

0 comments on commit e2778cd

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