mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 953005 - part1 - [B2G] enhance the initialization of MobileConnectionArray to improve performance. r=khuey
This commit is contained in:
parent
15182b8e81
commit
a90c2e5d9b
@ -33,16 +33,13 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileConnectionArray)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
MobileConnectionArray::MobileConnectionArray(nsPIDOMWindow* aWindow)
|
||||
: mWindow(aWindow)
|
||||
: mWindow(aWindow), mInitialized(false)
|
||||
{
|
||||
int32_t numRil = mozilla::Preferences::GetInt("ril.numRadioInterfaces", 1);
|
||||
uint32_t numRil = mozilla::Preferences::GetUint("ril.numRadioInterfaces", 1);
|
||||
MOZ_ASSERT(numRil > 0);
|
||||
|
||||
for (int32_t id = 0; id < numRil; id++) {
|
||||
nsRefPtr<MobileConnection> mobileConnection = new MobileConnection(id);
|
||||
mobileConnection->Init(aWindow);
|
||||
mMobileConnections.AppendElement(mobileConnection);
|
||||
}
|
||||
bool ret = mMobileConnections.SetLength(numRil);
|
||||
MOZ_ASSERT(ret);
|
||||
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
@ -52,12 +49,27 @@ MobileConnectionArray::~MobileConnectionArray()
|
||||
DropConnections();
|
||||
}
|
||||
|
||||
void
|
||||
MobileConnectionArray::Init()
|
||||
{
|
||||
mInitialized = true;
|
||||
|
||||
for (uint32_t id = 0; id < mMobileConnections.Length(); id++) {
|
||||
nsRefPtr<MobileConnection> mobileConnection = new MobileConnection(id);
|
||||
mobileConnection->Init(mWindow);
|
||||
mMobileConnections[id] = mobileConnection;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MobileConnectionArray::DropConnections()
|
||||
{
|
||||
for (uint32_t i = 0; i < mMobileConnections.Length(); i++) {
|
||||
mMobileConnections[i]->Shutdown();
|
||||
if (mInitialized) {
|
||||
for (uint32_t i = 0; i < mMobileConnections.Length(); i++) {
|
||||
mMobileConnections[i]->Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
mMobileConnections.Clear();
|
||||
}
|
||||
|
||||
@ -75,7 +87,7 @@ MobileConnectionArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
}
|
||||
|
||||
nsIDOMMozMobileConnection*
|
||||
MobileConnectionArray::Item(uint32_t aIndex) const
|
||||
MobileConnectionArray::Item(uint32_t aIndex)
|
||||
{
|
||||
bool unused;
|
||||
return IndexedGetter(aIndex, unused);
|
||||
@ -88,8 +100,12 @@ MobileConnectionArray::Length() const
|
||||
}
|
||||
|
||||
nsIDOMMozMobileConnection*
|
||||
MobileConnectionArray::IndexedGetter(uint32_t aIndex, bool& aFound) const
|
||||
MobileConnectionArray::IndexedGetter(uint32_t aIndex, bool& aFound)
|
||||
{
|
||||
if (!mInitialized) {
|
||||
Init();
|
||||
}
|
||||
|
||||
aFound = false;
|
||||
aFound = aIndex < mMobileConnections.Length();
|
||||
|
||||
|
@ -34,18 +34,24 @@ public:
|
||||
|
||||
// WebIDL
|
||||
nsIDOMMozMobileConnection*
|
||||
Item(uint32_t aIndex) const;
|
||||
Item(uint32_t aIndex);
|
||||
|
||||
uint32_t
|
||||
Length() const;
|
||||
|
||||
nsIDOMMozMobileConnection*
|
||||
IndexedGetter(uint32_t aIndex, bool& aFound) const;
|
||||
IndexedGetter(uint32_t aIndex, bool& aFound);
|
||||
|
||||
private:
|
||||
~MobileConnectionArray();
|
||||
|
||||
void DropConnections();
|
||||
void
|
||||
Init();
|
||||
|
||||
void
|
||||
DropConnections();
|
||||
|
||||
bool mInitialized;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||
nsTArray<nsRefPtr<MobileConnection>> mMobileConnections;
|
||||
|
Loading…
Reference in New Issue
Block a user