diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2024-03-04 19:15:43 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-05 08:57:34 +0100 |
commit | 571a1ab88a41bfc4f8024bd1531c9f34b1023e43 (patch) | |
tree | 9ac9044840b1232f6ec1ee5fbe7ccc2b6db535df /vcl | |
parent | ca781250bbf4435710b22bb6f06ed817b44fb891 (diff) |
reduce heap allocation in JSDialogNotifyIdle
makes the code simpler too
Change-Id: Ic452895a20fb2908f7383082069a84ef3fa6a4d1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164395
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
(cherry picked from commit 70f2c6f87ae3dd6c8e4b808cbee3ab81f17f6a36)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164380
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/jsdialog/jsdialogbuilder.hxx | 19 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 156 |
2 files changed, 81 insertions, 94 deletions
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index edd49c1804a7..7ef9c1cfc833 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -125,16 +125,15 @@ public: std::unique_ptr<jsdialog::ActionDataMap> pData = nullptr); private: - void send(tools::JsonWriter& aJsonWriter); - std::unique_ptr<tools::JsonWriter> generateFullUpdate() const; - std::unique_ptr<tools::JsonWriter> generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const; - std::unique_ptr<tools::JsonWriter> generateCloseMessage() const; - std::unique_ptr<tools::JsonWriter> - generateActionMessage(VclPtr<vcl::Window> pWindow, - std::unique_ptr<jsdialog::ActionDataMap> pData) const; - std::unique_ptr<tools::JsonWriter> - generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString sParentId, OUString sCloseId) const; - std::unique_ptr<tools::JsonWriter> generateClosePopupMessage(OUString sWindowId) const; + void send(const OString& sMsg); + OString generateFullUpdate() const; + OString generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const; + OString generateCloseMessage() const; + OString generateActionMessage(VclPtr<vcl::Window> pWindow, + std::unique_ptr<jsdialog::ActionDataMap> pData) const; + OString generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString sParentId, + OUString sCloseId) const; + OString generateClosePopupMessage(OUString sWindowId) const; }; class JSDialogSender diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index f5e3a9c65325..7eda7861fc8d 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -81,31 +81,22 @@ JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> aNotifierWindow, void JSDialogNotifyIdle::forceUpdate() { m_bForce = true; } -void JSDialogNotifyIdle::send(tools::JsonWriter& aJsonWriter) +void JSDialogNotifyIdle::send(const OString& sMsg) { if (!m_aNotifierWindow) { - aJsonWriter.finishAndGetAsOString(); return; } const vcl::ILibreOfficeKitNotifier* pNotifier = m_aNotifierWindow->GetLOKNotifier(); if (pNotifier) { - if (m_bForce || !aJsonWriter.isDataEquals(m_LastNotificationMessage)) + if (m_bForce || sMsg != m_LastNotificationMessage) { m_bForce = false; - m_LastNotificationMessage = aJsonWriter.finishAndGetAsOString(); + m_LastNotificationMessage = sMsg; pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, m_LastNotificationMessage); } - else - { - aJsonWriter.finishAndGetAsOString(); - } - } - else - { - aJsonWriter.finishAndGetAsOString(); } } @@ -138,91 +129,89 @@ void JSDialogNotifyIdle::sendMessage(jsdialog::MessageType eType, VclPtr<vcl::Wi m_aMessageQueue.push_back(aMessage); } -std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateFullUpdate() const +OString JSDialogNotifyIdle::generateFullUpdate() const { - std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter()); - if (!m_aContentWindow || !m_aNotifierWindow) - return aJsonWriter; + return OString(); - m_aContentWindow->DumpAsPropertyTree(*aJsonWriter); + tools::JsonWriter aJsonWriter; + + m_aContentWindow->DumpAsPropertyTree(aJsonWriter); if (m_aNotifierWindow) - aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId()); - aJsonWriter->put("jsontype", m_sTypeOfJSON); + aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId()); + aJsonWriter.put("jsontype", m_sTypeOfJSON); - return aJsonWriter; + return aJsonWriter.finishAndGetAsOString(); } -std::unique_ptr<tools::JsonWriter> -JSDialogNotifyIdle::generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const +OString JSDialogNotifyIdle::generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const { - std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter()); - if (!pWindow || !m_aNotifierWindow) - return aJsonWriter; + return OString(); - aJsonWriter->put("jsontype", m_sTypeOfJSON); - aJsonWriter->put("action", "update"); + tools::JsonWriter aJsonWriter; + + aJsonWriter.put("jsontype", m_sTypeOfJSON); + aJsonWriter.put("action", "update"); if (m_aNotifierWindow) - aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId()); + aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId()); { - auto aEntries = aJsonWriter->startNode("control"); - pWindow->DumpAsPropertyTree(*aJsonWriter); + auto aEntries = aJsonWriter.startNode("control"); + pWindow->DumpAsPropertyTree(aJsonWriter); } - return aJsonWriter; + return aJsonWriter.finishAndGetAsOString(); } -std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateCloseMessage() const +OString JSDialogNotifyIdle::generateCloseMessage() const { - std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter()); + tools::JsonWriter aJsonWriter; if (m_aNotifierWindow) - aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId()); - aJsonWriter->put("jsontype", m_sTypeOfJSON); - aJsonWriter->put("action", "close"); + aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId()); + aJsonWriter.put("jsontype", m_sTypeOfJSON); + aJsonWriter.put("action", "close"); - return aJsonWriter; + return aJsonWriter.finishAndGetAsOString(); } -std::unique_ptr<tools::JsonWriter> +OString JSDialogNotifyIdle::generateActionMessage(VclPtr<vcl::Window> pWindow, std::unique_ptr<jsdialog::ActionDataMap> pData) const { - std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter()); + tools::JsonWriter aJsonWriter; - aJsonWriter->put("jsontype", m_sTypeOfJSON); - aJsonWriter->put("action", "action"); + aJsonWriter.put("jsontype", m_sTypeOfJSON); + aJsonWriter.put("action", "action"); if (m_aNotifierWindow) - aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId()); + aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId()); { - auto aDataNode = aJsonWriter->startNode("data"); - aJsonWriter->put("control_id", pWindow->get_id()); + auto aDataNode = aJsonWriter.startNode("data"); + aJsonWriter.put("control_id", pWindow->get_id()); for (auto it = pData->begin(); it != pData->end(); it++) - aJsonWriter->put(it->first, it->second); + aJsonWriter.put(it->first, it->second); } - return aJsonWriter; + return aJsonWriter.finishAndGetAsOString(); } -std::unique_ptr<tools::JsonWriter> -JSDialogNotifyIdle::generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString sParentId, - OUString sCloseId) const +OString JSDialogNotifyIdle::generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString sParentId, + OUString sCloseId) const { - std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter()); - if (!pWindow || !m_aNotifierWindow) - return aJsonWriter; + return OString(); if (!pWindow->GetParentWithLOKNotifier()) - return aJsonWriter; + return OString(); + + tools::JsonWriter aJsonWriter; { - auto aChildren = aJsonWriter->startArray("children"); + auto aChildren = aJsonWriter.startArray("children"); { - auto aStruct = aJsonWriter->startStruct(); - pWindow->DumpAsPropertyTree(*aJsonWriter); + auto aStruct = aJsonWriter.startStruct(); + pWindow->DumpAsPropertyTree(aJsonWriter); } } @@ -239,37 +228,36 @@ JSDialogNotifyIdle::generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString s if (pDockingWindow) { Point aPos = pDockingWindow->GetFloatingPos(); - aJsonWriter->put("posx", aPos.getX()); - aJsonWriter->put("posy", aPos.getY()); + aJsonWriter.put("posx", aPos.getX()); + aJsonWriter.put("posy", aPos.getY()); if (!pDockingWindow->IsVisible()) - aJsonWriter->put("visible", "false"); + aJsonWriter.put("visible", "false"); } } - aJsonWriter->put("jsontype", "dialog"); - aJsonWriter->put("type", "modalpopup"); - aJsonWriter->put("cancellable", true); - aJsonWriter->put("popupParent", sParentId); - aJsonWriter->put("clickToClose", sCloseId); - aJsonWriter->put("id", pWindow->GetParentWithLOKNotifier()->GetLOKWindowId()); + aJsonWriter.put("jsontype", "dialog"); + aJsonWriter.put("type", "modalpopup"); + aJsonWriter.put("cancellable", true); + aJsonWriter.put("popupParent", sParentId); + aJsonWriter.put("clickToClose", sCloseId); + aJsonWriter.put("id", pWindow->GetParentWithLOKNotifier()->GetLOKWindowId()); - return aJsonWriter; + return aJsonWriter.finishAndGetAsOString(); } -std::unique_ptr<tools::JsonWriter> -JSDialogNotifyIdle::generateClosePopupMessage(OUString sWindowId) const +OString JSDialogNotifyIdle::generateClosePopupMessage(OUString sWindowId) const { - std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter()); - if (!m_aNotifierWindow) - return aJsonWriter; + return OString(); + + tools::JsonWriter aJsonWriter; - aJsonWriter->put("jsontype", "dialog"); - aJsonWriter->put("type", "modalpopup"); - aJsonWriter->put("action", "close"); - aJsonWriter->put("id", sWindowId); + aJsonWriter.put("jsontype", "dialog"); + aJsonWriter.put("type", "modalpopup"); + aJsonWriter.put("action", "close"); + aJsonWriter.put("id", sWindowId); - return aJsonWriter; + return aJsonWriter.finishAndGetAsOString(); } void JSDialogNotifyIdle::Invoke() @@ -291,29 +279,29 @@ void JSDialogNotifyIdle::Invoke() switch (eType) { case jsdialog::MessageType::FullUpdate: - send(*generateFullUpdate()); + send(generateFullUpdate()); break; case jsdialog::MessageType::WidgetUpdate: - send(*generateWidgetUpdate(rMessage.m_pWindow)); + send(generateWidgetUpdate(rMessage.m_pWindow)); break; case jsdialog::MessageType::Close: - send(*generateCloseMessage()); + send(generateCloseMessage()); break; case jsdialog::MessageType::Action: - send(*generateActionMessage(rMessage.m_pWindow, std::move(rMessage.m_pData))); + send(generateActionMessage(rMessage.m_pWindow, std::move(rMessage.m_pData))); break; case jsdialog::MessageType::Popup: - send(*generatePopupMessage(rMessage.m_pWindow, - (*rMessage.m_pData)[PARENT_ID ""_ostr], - (*rMessage.m_pData)[CLOSE_ID ""_ostr])); + send(generatePopupMessage(rMessage.m_pWindow, + (*rMessage.m_pData)[PARENT_ID ""_ostr], + (*rMessage.m_pData)[CLOSE_ID ""_ostr])); break; case jsdialog::MessageType::PopupClose: - send(*generateClosePopupMessage((*rMessage.m_pData)[WINDOW_ID ""_ostr])); + send(generateClosePopupMessage((*rMessage.m_pData)[WINDOW_ID ""_ostr])); break; } } |