From 1585ffa47e7b345f5869bbecd873ffbf59a8d20c Mon Sep 17 00:00:00 2001 From: Andrew Gallagher Date: Wed, 9 Jan 2013 17:37:57 -0800 Subject: [PATCH] fbstring: avoid including Likely.h Summary: Including Likely.h causes issues when import fbstring into libstdc++, so provide internal definitions for these macros that we can undef afterwards. Test Plan: built folly Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D675366 --- folly/FBString.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index 931c4c3b..a0a86f46 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2013 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,12 +87,16 @@ #include #include "folly/Traits.h" -#include "folly/Likely.h" #include "folly/Malloc.h" #include "folly/Hash.h" #endif +// We defined these here rather than including Likely.h to avoid +// redefinition errors when fbstring is imported into libstdc++. +#define FBSTRING_LIKELY(x) (__builtin_expect((x), 1)) +#define FBSTRING_UNLIKELY(x) (__builtin_expect((x), 0)) + #include #include #include @@ -1259,7 +1263,7 @@ public: Invariant checker(*this); (void) checker; #endif - if (UNLIKELY(!n)) { + if (FBSTRING_UNLIKELY(!n)) { // Unlikely but must be done return *this; } @@ -1272,7 +1276,7 @@ public: // over pointers. See discussion at http://goo.gl/Cy2ya for more // info. std::less_equal le; - if (UNLIKELY(le(oldData, s) && !le(oldData + oldSize, s))) { + if (FBSTRING_UNLIKELY(le(oldData, s) && !le(oldData + oldSize, s))) { assert(le(s + n, oldData + oldSize)); const size_type offset = s - oldData; store_.reserve(oldSize + n); @@ -2323,4 +2327,7 @@ struct hash< ::folly::fbstring> { #endif // _LIBSTDCXX_FBSTRING +#undef FBSTRING_LIKELY +#undef FBSTRING_UNLIKELY + #endif // FOLLY_BASE_FBSTRING_H_ -- 2.34.1