Bug 1352687, try to recycle HTMLInputElement's nsTextEditorState, r=baku

This commit is contained in:
Olli Pettay
2017-04-03 20:40:48 +03:00
parent 6f72c6a90a
commit c6c840deae
5 changed files with 79 additions and 4 deletions

View File

@@ -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);
}