зеркало из https://github.com/mozilla/gecko-dev.git
Add NS_LIKELY and NS_UNLIKELY macros that can be used to give the compiler branch probability information. Make NS_SUCCEEDED and NS_FAILED use these macros so that we optimize for the success case. Bug 236753, r+sr=dbaron.
This commit is contained in:
Родитель
93df2945c9
Коммит
146a922871
|
@ -106,8 +106,8 @@
|
|||
* @name Standard Error Handling Macros
|
||||
*/
|
||||
|
||||
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
|
||||
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
|
||||
#define NS_FAILED(_nsresult) (NS_UNLIKELY((_nsresult) & 0x80000000))
|
||||
#define NS_SUCCEEDED(_nsresult) (NS_LIKELY(!((_nsresult) & 0x80000000)))
|
||||
|
||||
/**
|
||||
* @name Severity Code. This flag identifies the level of warning
|
||||
|
|
|
@ -368,5 +368,27 @@ typedef PRUint32 nsresult;
|
|||
#define NS_PTR_TO_INT32(x) ((char *)(x) - (char *)0)
|
||||
#define NS_INT32_TO_PTR(x) ((void *)((char *)0 + (x)))
|
||||
|
||||
/*
|
||||
* These macros allow you to give a hint to the compiler about branch
|
||||
* probability so that it can better optimize. Use them like this:
|
||||
*
|
||||
* if (NS_LIKELY(v == 1)) {
|
||||
* ... expected code path ...
|
||||
* }
|
||||
*
|
||||
* if (NS_UNLIKELY(v == 0)) {
|
||||
* ... non-expected code path ...
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2)
|
||||
#define NS_LIKELY(x) (__builtin_expect((x), 1))
|
||||
#define NS_UNLIKELY(x) (__builtin_expect((x), 0))
|
||||
#else
|
||||
#define NS_LIKELY(x) (x)
|
||||
#define NS_UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* nscore_h___ */
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче