[Libreoffice-commits] core.git: 3 commits - desktop/inc desktop/qa desktop/source include/LibreOfficeKit sfx2/source

Jan Holesovsky kendy at collabora.com
Tue Jan 31 16:55:17 UTC 2017


 desktop/inc/lib/init.hxx                    |    4 --
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   45 -------------------------
 desktop/source/lib/init.cxx                 |   50 +++++++++++-----------------
 include/LibreOfficeKit/LibreOfficeKit.h     |   10 -----
 include/LibreOfficeKit/LibreOfficeKit.hxx   |   10 -----
 sfx2/source/view/lokhelper.cxx              |   14 ++-----
 6 files changed, 24 insertions(+), 109 deletions(-)

New commits:
commit 20910ea89efb01406e35e9d942613123f78b637f
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Jan 31 17:33:49 2017 +0100

    Replace a terribly expensive json parsing with a peek for the value.
    
    We should reduce the amount of callbacks from the core in the first place, so
    that we don't have to deduplicate this much here, but this already helps a
    lot.
    
    Change-Id: Idf4a3681ac0f47536e00c1d97152f3f8bb99894b

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 57067fa..d879798 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -446,10 +446,26 @@ bool lcl_isViewCallbackType(const int type)
 
 int lcl_getViewId(const std::string& payload)
 {
-    boost::property_tree::ptree aTree;
-    std::stringstream aStream(payload);
-    boost::property_tree::read_json(aStream, aTree);
-    return aTree.get<int>("viewId");
+    // this is a cheap way how to get the viewId from a JSON message; proper
+    // parsing is terribly expensive, and we just need the viewId here
+    size_t viewIdPos = payload.find("viewId");
+    if (viewIdPos == std::string::npos)
+        return 0;
+
+    size_t numberPos = payload.find(":", viewIdPos + 6);
+    if (numberPos == std::string::npos)
+        return 0;
+
+    for (++numberPos; numberPos < payload.length(); ++numberPos)
+    {
+        if (payload[numberPos] == ',' || payload[numberPos] == '}' || (payload[numberPos] >= '0' && payload[numberPos] <= '9'))
+            break;
+    }
+
+    if (numberPos < payload.length() && payload[numberPos] >= '0' && payload[numberPos] <= '9')
+        return std::stoi(payload.substr(numberPos));
+
+    return 0;
 }
 
 }  // end anonymous namespace
commit 230f04e92d3a3c492e12e0ef2392fc45c73dd762
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Jan 31 16:47:54 2017 +0100

    Build the json message a much less expensive way.
    
    Change-Id: I10911deb52f6a0c65262f9d6af459cf6ddd2fae9

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 4aa35af..bfcd000 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -9,8 +9,6 @@
 
 #include <sfx2/lokhelper.hxx>
 
-#include <boost/property_tree/json_parser.hpp>
-
 #include <com/sun/star/frame/Desktop.hpp>
 
 #include <comphelper/processfactory.hxx>
@@ -112,14 +110,10 @@ bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
 
 void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload)
 {
-    boost::property_tree::ptree aTree;
-    aTree.put("viewId", SfxLokHelper::getView(pThisView));
-    aTree.put(rKey.getStr(), rPayload.getStr());
-    aTree.put("part", pThisView->getPart());
-    aTree.put(rKey.getStr(), rPayload.getStr());
-    std::stringstream aStream;
-    boost::property_tree::write_json(aStream, aTree);
-    OString aPayload = aStream.str().c_str();
+    OString aPayload = OString("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView(pThisView)) +
+        "\", \"part\": \"" + OString::number(pThisView->getPart()) +
+        "\", \"" + rKey + "\": \"" + rPayload + "\" }";
+
     pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr());
 }
 
commit be71e2b860e8ec5debc60bdcbda3e3fa5f8cd528
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Jan 27 19:19:43 2017 +0100

    Revert "Lok: support for batch API calls"
    
    This was for the moment removed from the online.git, so let's disable the API
    bits too before it shows this is really necessary.  Reverts also:
    Revert "Lok: unittest batch API"
    
    Change-Id: I7bf3fe62d1e73b6f233992d51f587868a78f4bec

diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index bfe9954..302f54d 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -41,10 +41,6 @@ namespace desktop {
         void setEventLatch(const bool bEventLatch)
         {
             m_bEventLatch = bEventLatch;
-            if (!IsActive())
-            {
-                Start();
-            }
         }
 
         bool isEventLatchOn() const { return m_bEventLatch; }
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index a1a769b..4312089 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -96,7 +96,6 @@ public:
     void testContextMenuImpress();
     void testNotificationCompression();
     void testTileInvalidationCompression();
-    void testBatching();
     void testPartInInvalidation();
     void testRedlineWriter();
     void testTrackChanges();
@@ -133,7 +132,6 @@ public:
     CPPUNIT_TEST(testContextMenuImpress);
     CPPUNIT_TEST(testNotificationCompression);
     CPPUNIT_TEST(testTileInvalidationCompression);
-    CPPUNIT_TEST(testBatching);
     CPPUNIT_TEST(testPartInInvalidation);
     CPPUNIT_TEST(testRedlineWriter);
     CPPUNIT_TEST(testTrackChanges);
@@ -1588,49 +1586,6 @@ void DesktopLOKTest::testPartInInvalidation()
     }
 }
 
-void DesktopLOKTest::testBatching()
-{
-    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
-
-    comphelper::LibreOfficeKit::setPartInInvalidation(true);
-    comphelper::ScopeGuard aGuard([]()
-    {
-        comphelper::LibreOfficeKit::setPartInInvalidation(false);
-    });
-
-    std::vector<std::tuple<int, std::string>> notifs;
-    std::unique_ptr<CallbackFlushHandler> handler(new CallbackFlushHandler(pDocument, callbackCompressionTest, &notifs));
-
-    // Enable Batch mode.
-    handler->setEventLatch(true);
-
-    handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "0, 0, 239, 239, 0");
-    handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "EMPTY, 0");
-
-    Scheduler::ProcessEventsToIdle();
-
-    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), notifs.size());
-
-    handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "0, 0, 239, 240, 0");
-    handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "-121, -121, 300, 300, 0");
-    handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "0, 0, -32767, -32767, 0");
-
-    Scheduler::ProcessEventsToIdle();
-
-    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), notifs.size());
-
-    // Disable Batch mode.
-    handler->setEventLatch(false);
-
-    Scheduler::ProcessEventsToIdle();
-
-    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), notifs.size());
-
-    size_t i = 0;
-    CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_TILES, (int)std::get<0>(notifs[i]));
-    CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 1000000000, 1000000000, 0"), std::get<1>(notifs[i++]));
-}
-
 void DesktopLOKTest::testRedlineWriter()
 {
     // Load a Writer document, enable change recording and press a key.
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 2dcd59f..57067fa 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -537,8 +537,6 @@ static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis,
                           int* pFontWidth,
                           int* pFontHeight);
 static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart);
-static void doc_beginBatch(LibreOfficeKitDocument* pThis);
-static void doc_endBatch(LibreOfficeKitDocument* pThis);
 
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent)
     : mxComponent(xComponent)
@@ -585,8 +583,6 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
 
         m_pDocumentClass->renderFont = doc_renderFont;
         m_pDocumentClass->getPartHash = doc_getPartHash;
-        m_pDocumentClass->beginBatch = doc_beginBatch;
-        m_pDocumentClass->endBatch = doc_endBatch;
 
         gDocumentClass = m_pDocumentClass;
     }
@@ -2734,28 +2730,6 @@ unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/,
     return nullptr;
 }
 
-static void doc_beginBatch(LibreOfficeKitDocument* pThis)
-{
-    SolarMutexGuard aGuard;
-
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-    for (const auto& pair : pDocument->mpCallbackFlushHandlers)
-    {
-        pair.second->setEventLatch(true);
-    }
-}
-
-static void doc_endBatch(LibreOfficeKitDocument* pThis)
-{
-    SolarMutexGuard aGuard;
-
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-    for (const auto& pair : pDocument->mpCallbackFlushHandlers)
-    {
-        pair.second->setEventLatch(false);
-    }
-}
-
 static char* lo_getError (LibreOfficeKit *pThis)
 {
     SolarMutexGuard aGuard;
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 55cff72..c7a2130 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -250,16 +250,6 @@ struct _LibreOfficeKitDocumentClass
                        int* pArray,
                        size_t nSize);
 
-    /// Starts a batch of operations.
-    /// Events are emmitted only after ending the batch.
-    /// @see lok::Document::endBatch();
-    void (*beginBatch) (LibreOfficeKitDocument* pThis);
-
-    /// Ends a batch of operations.
-    /// @see lok::Document::beginBatch();
-    void (*endBatch) (LibreOfficeKitDocument* pThis);
-
-
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 46ecb5f..447f44b 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -452,16 +452,6 @@ public:
         return mpDoc->pClass->getViewIds(mpDoc, pArray, nSize);
     }
 
-    inline void beginBatch()
-    {
-        mpDoc->pClass->beginBatch(mpDoc);
-    }
-
-    inline void endBatch()
-    {
-        mpDoc->pClass->endBatch(mpDoc);
-    }
-
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 


More information about the Libreoffice-commits mailing list