mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Make NS_LIKELY/NS_UNLIKELY accept pointers etc and always return 0 or 1. b=340244 r+sr=darin
This commit is contained in:
parent
82109069db
commit
cca3292d36
@ -90,23 +90,27 @@ nsresult TextEditorTest::RunUnitTest(PRInt32 *outNumTests, PRInt32 *outNumTestsF
|
||||
result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
if (NS_FAILED(result))
|
||||
++(*outNumTestsFailed);
|
||||
|
||||
// insert some more text
|
||||
result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere"));
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
if (NS_FAILED(result))
|
||||
++(*outNumTestsFailed);
|
||||
|
||||
result = TestInsertBreak();
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
if (NS_FAILED(result))
|
||||
++(*outNumTestsFailed);
|
||||
|
||||
result = TestTextProperties();
|
||||
TEST_RESULT(result);
|
||||
(*outNumTests)++;
|
||||
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
|
||||
if (NS_FAILED(result))
|
||||
++(*outNumTestsFailed);
|
||||
|
||||
// get us back to the original document
|
||||
result = mEditor->Undo(12);
|
||||
|
@ -85,10 +85,6 @@ static nsresult pref_InitInitialObjects(void);
|
||||
*/
|
||||
|
||||
nsPrefService::nsPrefService()
|
||||
: mErrorOpeningUserPrefs(PR_FALSE)
|
||||
#if MOZ_PROFILESHARING
|
||||
, mErrorOpeningSharedUserPrefs(PR_FALSE)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@ -368,11 +364,7 @@ nsresult nsPrefService::ReadAndOwnUserPrefFile(nsIFile *aFile)
|
||||
gSharedPrefHandler->ReadingUserPrefs(PR_TRUE);
|
||||
#endif
|
||||
|
||||
// We need to track errors in reading the shared and the
|
||||
// non-shared files independently.
|
||||
// Set the appropriate member variable from it after reading.
|
||||
nsresult rv = openPrefFile(mCurrentFile);
|
||||
mErrorOpeningUserPrefs = NS_FAILED(rv);
|
||||
|
||||
#ifdef MOZ_PROFILESHARING
|
||||
gSharedPrefHandler->ReadingUserPrefs(PR_FALSE);
|
||||
@ -395,11 +387,7 @@ nsresult nsPrefService::ReadAndOwnSharedUserPrefFile(nsIFile *aFile)
|
||||
gSharedPrefHandler->ReadingUserPrefs(PR_TRUE);
|
||||
#endif
|
||||
|
||||
// We need to track errors in reading the shared and the
|
||||
// non-shared files independently.
|
||||
// Set the appropriate member variable from it after reading.
|
||||
nsresult rv = openPrefFile(mCurrentSharedFile);
|
||||
mErrorOpeningSharedUserPrefs = NS_FAILED(rv);
|
||||
|
||||
#ifdef MOZ_PROFILESHARING
|
||||
gSharedPrefHandler->ReadingUserPrefs(PR_FALSE);
|
||||
@ -468,14 +456,6 @@ nsresult nsPrefService::WritePrefFile(nsIFile* aFile)
|
||||
if (!gHashTable.ops)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
/* ?! Don't save (blank) user prefs if there was an error reading them */
|
||||
if (aFile == mCurrentFile && mErrorOpeningUserPrefs)
|
||||
return NS_OK;
|
||||
#if MOZ_PROFILESHARING
|
||||
if (aFile == mCurrentSharedFile && mErrorOpeningSharedUserPrefs)
|
||||
return NS_OK;
|
||||
#endif
|
||||
|
||||
// execute a "safe" save by saving through a tempfile
|
||||
rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStreamSink),
|
||||
aFile,
|
||||
@ -782,4 +762,3 @@ static nsresult pref_InitInitialObjects()
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,6 @@ protected:
|
||||
private:
|
||||
nsCOMPtr<nsIPrefBranch2> mRootBranch;
|
||||
nsCOMPtr<nsIFile> mCurrentFile;
|
||||
PRPackedBool mErrorOpeningUserPrefs;
|
||||
|
||||
PRPackedBool mErrorOpeningSharedUserPrefs;
|
||||
nsCOMPtr<nsIFile> mCurrentSharedFile;
|
||||
};
|
||||
|
||||
|
@ -108,6 +108,7 @@
|
||||
|
||||
/**
|
||||
* @name Standard Error Handling Macros
|
||||
* @return 0 or 1
|
||||
*/
|
||||
|
||||
#define NS_FAILED(_nsresult) (NS_UNLIKELY((_nsresult) & 0x80000000))
|
||||
|
@ -456,14 +456,17 @@ typedef PRUint32 nsrefcnt;
|
||||
* ... non-expected code path ...
|
||||
* }
|
||||
*
|
||||
* These macros are guaranteed to always return 0 or 1.
|
||||
* The NS_FAILED/NS_SUCCEEDED macros depends on this.
|
||||
* @return 0 or 1
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2)
|
||||
#define NS_LIKELY(x) (__builtin_expect((x), 1))
|
||||
#define NS_UNLIKELY(x) (__builtin_expect((x), 0))
|
||||
#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)
|
||||
#define NS_LIKELY(x) (!!(x))
|
||||
#define NS_UNLIKELY(x) (!!(x))
|
||||
#endif
|
||||
|
||||
#endif /* nscore_h___ */
|
||||
|
Loading…
Reference in New Issue
Block a user