Bug 1477579: Part 1 - Use literal strings for statically registered contract ID keys. r=froydnj

Most of our components are static, and registered using literal C strings. For
those components, we currently use a nsDependentCString as a key when creating
a hash entry, which leads to an unnecessary duplication. Using literal
CStrings instead avoids the duplication.

MozReview-Commit-ID: 5DOUF8ZQMlh

--HG--
extra : rebase_source : 57d151df64e29ee756f290e7eb047610b567ef04
This commit is contained in:
Kris Maglione 2018-07-22 10:54:56 -07:00
Родитель e0391b2197
Коммит 5302f88f24
1 изменённых файлов: 38 добавлений и 1 удалений

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

@ -57,6 +57,10 @@
#include "mozilla/Logging.h"
#include "LogModulePrefWatcher.h"
#ifdef MOZ_MEMORY
#include "mozmemory.h"
#endif
using namespace mozilla;
static LazyLogModule nsComponentManagerLog("nsComponentManager");
@ -468,6 +472,39 @@ ProcessSelectorMatches(Module::ProcessSelector aSelector)
static const int kModuleVersionWithSelector = 51;
template<typename T>
static void
AssertNotMallocAllocated(T* aPtr)
{
#if defined(DEBUG) && defined(MOZ_MEMORY)
jemalloc_ptr_info_t info;
jemalloc_ptr_info((void*)aPtr, &info);
MOZ_ASSERT(info.tag == TagUnknown);
#endif
}
template<typename T>
static void
AssertNotStackAllocated(T* aPtr)
{
// The main thread's stack should be allocated at the top of our address
// space. Anything stack allocated should be above us on the stack, and
// therefore above our first argument pointer.
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(uintptr_t(aPtr) < uintptr_t(&aPtr));
}
static inline nsCString
AsLiteralCString(const char* aStr)
{
AssertNotMallocAllocated(aStr);
AssertNotStackAllocated(aStr);
nsCString str;
str.AssignLiteral(aStr, strlen(aStr));
return str;
}
void
nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule,
FileLocation* aFile)
@ -583,7 +620,7 @@ nsComponentManagerImpl::RegisterContractIDLocked(
return;
}
mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
mContractIDs.Put(AsLiteralCString(aEntry->contractid), f);
}
static void