Bug 204114 - "nsUnicharUtils need to be threadsafe". r=smontagu.

This commit is contained in:
bent.mozilla%gmail.com 2006-06-21 15:25:17 +00:00
Родитель 07c2f8f972
Коммит 6fc2761be5
3 изменённых файлов: 39 добавлений и 55 удалений

Просмотреть файл

@ -173,12 +173,14 @@ PRUnichar nsCompressedMap::Lookup(
}
}
nsrefcnt nsCaseConversionImp2::gInit = 0;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCaseConversionImp2, nsICaseConversion)
NS_IMPL_ISUPPORTS1(nsCaseConversionImp2, nsICaseConversion)
static nsCompressedMap *gUpperMap = nsnull;
static nsCompressedMap *gLowerMap = nsnull;
static nsCompressedMap
gUpperMap(NS_REINTERPRET_CAST(const PRUnichar*, &gToUpper[0]),
gToUpperItems);
static nsCompressedMap
gLowerMap(NS_REINTERPRET_CAST(const PRUnichar*, &gToLower[0]),
gToLowerItems);
nsresult nsCaseConversionImp2::ToUpper(
PRUnichar aChar, PRUnichar* aReturn
@ -197,7 +199,7 @@ nsresult nsCaseConversionImp2::ToUpper(
}
else
{
*aReturn = gUpperMap->Map(aChar);
*aReturn = gUpperMap.Map(aChar);
}
return NS_OK;
}
@ -220,7 +222,7 @@ static PRUnichar FastToLower(
}
else
{
return gLowerMap->Map(aChar);
return gLowerMap.Map(aChar);
}
return NS_OK;
}
@ -259,7 +261,7 @@ nsresult nsCaseConversionImp2::ToTitle(
}
PRUnichar upper;
upper = gUpperMap->Map(aChar);
upper = gUpperMap.Map(aChar);
if( 0x01C0 == ( upper & 0xFFC0)) // 0x01Cx - 0x01Fx
{
@ -296,7 +298,7 @@ nsresult nsCaseConversionImp2::ToUpper(
}
else
{
aReturn[i] = gUpperMap->Map(aChar);
aReturn[i] = gUpperMap.Map(aChar);
}
}
return NS_OK;
@ -389,30 +391,10 @@ nsCaseConversionImp2::CaseInsensitiveCompare(const PRUnichar *aLeft,
return NS_OK;
}
nsCaseConversionImp2::nsCaseConversionImp2()
nsresult NS_NewCaseConversion(nsICaseConversion** oResult)
{
if (gInit++ == 0) {
gUpperMap = new nsCompressedMap(NS_REINTERPRET_CAST(const PRUnichar*, &gToUpper[0]), gToUpperItems);
gLowerMap = new nsCompressedMap(NS_REINTERPRET_CAST(const PRUnichar*, &gToLower[0]), gToLowerItems);
}
}
nsCaseConversionImp2::~nsCaseConversionImp2()
{
if (--gInit == 0) {
delete gUpperMap;
gUpperMap = nsnull;
delete gLowerMap;
gLowerMap = nsnull;
}
}
nsresult NS_NewCaseConversion(nsISupports** oResult)
{
if(!oResult)
return NS_ERROR_NULL_POINTER;
*oResult = new nsCaseConversionImp2();
if(*oResult)
NS_ADDREF(*oResult);
return (*oResult) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
NS_ENSURE_ARG_POINTER(oResult);
NS_NEWXPCOM(*oResult, nsCaseConversionImp2);
NS_IF_ADDREF(*oResult);
return *oResult ? NS_OK :NS_ERROR_OUT_OF_MEMORY;
}

Просмотреть файл

@ -49,8 +49,8 @@ class nsCaseConversionImp2 : public nsICaseConversion {
NS_DECL_ISUPPORTS
public:
nsCaseConversionImp2();
virtual ~nsCaseConversionImp2();
nsCaseConversionImp2() { };
virtual ~nsCaseConversionImp2() { };
NS_IMETHOD ToUpper(PRUnichar aChar, PRUnichar* aReturn);
@ -67,8 +67,6 @@ public:
PRUint32 aLen, PRBool aStartInWordBoundary = PR_TRUE);
NS_IMETHOD CaseInsensitiveCompare(const PRUnichar* aLeft, const PRUnichar* aRight, PRUint32 aLength, PRInt32 *aResult);
private:
static nsrefcnt gInit;
};
#endif

Просмотреть файл

@ -73,26 +73,30 @@ public:
};
NS_IMPL_ISUPPORTS1(nsShutdownObserver, nsIObserver)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsShutdownObserver, nsIObserver)
static nsresult NS_InitCaseConversion() {
if (gCaseConv) return NS_OK;
nsresult rv;
rv = CallGetService(NS_UNICHARUTIL_CONTRACTID, &gCaseConv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_SUCCEEDED(rv)) {
nsShutdownObserver *observer = new nsShutdownObserver();
if (observer)
obs->AddObserver(observer, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
if (gCaseConv)
return NS_OK;
nsresult rv = CallGetService(NS_UNICHARUTIL_CONTRACTID, &gCaseConv);
if (NS_FAILED(rv)) {
gCaseConv = nsnull;
return rv;
}
return NS_OK;
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIObserver> observer;
NS_NEWXPCOM(observer, nsShutdownObserver);
if (observer)
obs->AddObserver(observer, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
PR_FALSE);
}
return NS_OK;
}
void