Bug 802473 - Make NS_FAILED return 0 or 1 (false/true typed as bool for C++). Use branch prediction macros for NS_FAILED/NS_SUCCEEDED. r=ehsan,bsmedberg
authorMats Palmgren <matspal@gmail.com>
Thu, 18 Oct 2012 02:43:06 +0200
changeset 110756 d9871b40e0f6d1192d5602fed7152d459cd052bf
parent 110755 4686dc4138ba97ce3e138c73b6c05bc541c3bd3b
child 110757 2a96aeb11ad44ab6ac55c32a2bf177ad89dabb32
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersehsan, bsmedberg
bugs802473
milestone19.0a1
Bug 802473 - Make NS_FAILED return 0 or 1 (false/true typed as bool for C++). Use branch prediction macros for NS_FAILED/NS_SUCCEEDED. r=ehsan,bsmedberg
xpcom/base/nsError.h
--- a/xpcom/base/nsError.h
+++ b/xpcom/base/nsError.h
@@ -141,30 +141,29 @@
 #endif
 
 #undef SUCCESS_OR_FAILURE
 #undef SUCCESS
 #undef FAILURE
 
 /**
  * @name Standard Error Handling Macros
- * @return 0 or 1
+ * @return 0 or 1 (false/true with bool type for C++)
  */
 
 #ifdef __cplusplus
-inline int NS_FAILED(nsresult _nsresult) {
+inline uint32_t NS_FAILED_impl(nsresult _nsresult) {
   return static_cast<uint32_t>(_nsresult) & 0x80000000;
 }
-
-inline int NS_SUCCEEDED(nsresult _nsresult) {
-  return !(static_cast<uint32_t>(_nsresult) & 0x80000000);
-}
+#define NS_FAILED(_nsresult)    ((bool)NS_UNLIKELY(NS_FAILED_impl(_nsresult)))
+#define NS_SUCCEEDED(_nsresult) ((bool)NS_LIKELY(!NS_FAILED_impl(_nsresult)))
 #else
-#define NS_FAILED(_nsresult)    (NS_UNLIKELY((_nsresult) & 0x80000000))
-#define NS_SUCCEEDED(_nsresult) (NS_LIKELY(!((_nsresult) & 0x80000000)))
+#define NS_FAILED_impl(_nsresult) ((_nsresult) & 0x80000000)
+#define NS_FAILED(_nsresult)    (NS_UNLIKELY(NS_FAILED_impl(_nsresult)))
+#define NS_SUCCEEDED(_nsresult) (NS_LIKELY(!NS_FAILED_impl(_nsresult)))
 #endif
 
 /**
  * @name Standard Error Generating Macros
  */
 
 #define NS_ERROR_GENERATE(sev, module, code) \
     (nsresult)(((uint32_t)(sev) << 31) | \