Bug 1352687, try to recycle HTMLInputElement's nsTextEditorState, r=baku
This commit is contained in:
@@ -1048,6 +1048,28 @@ static nsresult FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget,
|
||||
const nsAString& aEventType);
|
||||
#endif
|
||||
|
||||
nsTextEditorState* HTMLInputElement::sCachedTextEditorState = nullptr;
|
||||
bool HTMLInputElement::sShutdown = false;
|
||||
|
||||
/* static */ void
|
||||
HTMLInputElement::ReleaseTextEditorState(nsTextEditorState* aState)
|
||||
{
|
||||
if (!sShutdown && !sCachedTextEditorState) {
|
||||
aState->PrepareForReuse();
|
||||
sCachedTextEditorState = aState;
|
||||
} else {
|
||||
delete aState;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
HTMLInputElement::Shutdown()
|
||||
{
|
||||
sShutdown = true;
|
||||
delete sCachedTextEditorState;
|
||||
sCachedTextEditorState = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
// construction, destruction
|
||||
//
|
||||
@@ -1079,7 +1101,8 @@ HTMLInputElement::HTMLInputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
|
||||
, mSelectionCached(true)
|
||||
{
|
||||
// We are in a type=text so we now we currenty need a nsTextEditorState.
|
||||
mInputData.mState = new nsTextEditorState(this);
|
||||
mInputData.mState =
|
||||
nsTextEditorState::Construct(this, &sCachedTextEditorState);
|
||||
|
||||
if (!gUploadLastDir)
|
||||
HTMLInputElement::InitUploadLastDir();
|
||||
@@ -1112,7 +1135,7 @@ HTMLInputElement::FreeData()
|
||||
mInputData.mValue = nullptr;
|
||||
} else {
|
||||
UnbindFromFrame(nullptr);
|
||||
delete mInputData.mState;
|
||||
ReleaseTextEditorState(mInputData.mState);
|
||||
mInputData.mState = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -5027,7 +5050,8 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify)
|
||||
|
||||
if (IsSingleLineTextControl()) {
|
||||
|
||||
mInputData.mState = new nsTextEditorState(this);
|
||||
mInputData.mState =
|
||||
nsTextEditorState::Construct(this, &sCachedTextEditorState);
|
||||
if (!sp.IsDefault()) {
|
||||
mInputData.mState->SetSelectionProperties(sp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user