Kaydet (Commit) 1666b302 authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

LOK: Use a struct instead of std::pair to support caching

Change-Id: I48e8de8709e017f2667c0bf2c850004128c840d1
Reviewed-on: https://gerrit.libreoffice.org/67890
Tested-by: Jenkins
Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst b1a3db96
...@@ -90,7 +90,19 @@ namespace desktop { ...@@ -90,7 +90,19 @@ namespace desktop {
void addViewStates(int viewId); void addViewStates(int viewId);
void removeViewStates(int viewId); void removeViewStates(int viewId);
typedef std::vector<std::pair<int, std::string>> queue_type; struct CallbackData
{
CallbackData(int type, const std::string& payload)
: Type(type)
, PayloadString(payload)
{
}
int Type;
std::string PayloadString;
};
typedef std::vector<CallbackData> queue_type;
private: private:
void removeAll(const std::function<bool (const queue_type::value_type&)>& rTestFunc); void removeAll(const std::function<bool (const queue_type::value_type&)>& rTestFunc);
......
...@@ -906,9 +906,9 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -906,9 +906,9 @@ void CallbackFlushHandler::queue(const int type, const char* data)
case LOK_CALLBACK_WINDOW: case LOK_CALLBACK_WINDOW:
{ {
const auto& pos = std::find_if(m_queue.rbegin(), m_queue.rend(), const auto& pos = std::find_if(m_queue.rbegin(), m_queue.rend(),
[type] (const queue_type::value_type& elem) { return (elem.first == type); }); [type] (const queue_type::value_type& elem) { return (elem.Type == type); });
if (pos != m_queue.rend() && pos->second == payload) if (pos != m_queue.rend() && pos->PayloadString == payload)
{ {
SAL_INFO("lok", "Skipping queue duplicate [" << type << + "]: [" << payload << "]."); SAL_INFO("lok", "Skipping queue duplicate [" << type << + "]: [" << payload << "].");
return; return;
...@@ -920,14 +920,14 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -920,14 +920,14 @@ void CallbackFlushHandler::queue(const int type, const char* data)
if (type == LOK_CALLBACK_TEXT_SELECTION && payload.empty()) if (type == LOK_CALLBACK_TEXT_SELECTION && payload.empty())
{ {
const auto& posStart = std::find_if(m_queue.rbegin(), m_queue.rend(), const auto& posStart = std::find_if(m_queue.rbegin(), m_queue.rend(),
[] (const queue_type::value_type& elem) { return (elem.first == LOK_CALLBACK_TEXT_SELECTION_START); }); [] (const queue_type::value_type& elem) { return (elem.Type == LOK_CALLBACK_TEXT_SELECTION_START); });
if (posStart != m_queue.rend()) if (posStart != m_queue.rend())
posStart->second = ""; posStart->PayloadString.clear();
const auto& posEnd = std::find_if(m_queue.rbegin(), m_queue.rend(), const auto& posEnd = std::find_if(m_queue.rbegin(), m_queue.rend(),
[] (const queue_type::value_type& elem) { return (elem.first == LOK_CALLBACK_TEXT_SELECTION_END); }); [] (const queue_type::value_type& elem) { return (elem.Type == LOK_CALLBACK_TEXT_SELECTION_END); });
if (posEnd != m_queue.rend()) if (posEnd != m_queue.rend())
posEnd->second = ""; posEnd->PayloadString.clear();
} }
// When payload is empty discards any previous state. // When payload is empty discards any previous state.
...@@ -942,7 +942,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -942,7 +942,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR: case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
case LOK_CALLBACK_INVALIDATE_TILES: case LOK_CALLBACK_INVALIDATE_TILES:
SAL_INFO("lok", "Removing dups of [" << type << "]: [" << payload << "]."); SAL_INFO("lok", "Removing dups of [" << type << "]: [" << payload << "].");
removeAll([type] (const queue_type::value_type& elem) { return (elem.first == type); }); removeAll([type] (const queue_type::value_type& elem) { return (elem.Type == type); });
break; break;
} }
} }
...@@ -965,7 +965,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -965,7 +965,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE: case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
case LOK_CALLBACK_RULER_UPDATE: case LOK_CALLBACK_RULER_UPDATE:
{ {
removeAll([type] (const queue_type::value_type& elem) { return (elem.first == type); }); removeAll([type] (const queue_type::value_type& elem) { return (elem.Type == type); });
} }
break; break;
...@@ -981,7 +981,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -981,7 +981,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
const int nViewId = lcl_getViewId(payload); const int nViewId = lcl_getViewId(payload);
removeAll( removeAll(
[type, nViewId] (const queue_type::value_type& elem) { [type, nViewId] (const queue_type::value_type& elem) {
return (elem.first == type && nViewId == lcl_getViewId(elem.second)); return (elem.Type == type && nViewId == lcl_getViewId(elem.PayloadString));
} }
); );
} }
...@@ -991,7 +991,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -991,7 +991,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
{ {
removeAll( removeAll(
[type, &payload] (const queue_type::value_type& elem) { [type, &payload] (const queue_type::value_type& elem) {
return (elem.first == type && elem.second == payload); return (elem.Type == type && elem.PayloadString == payload);
} }
); );
} }
...@@ -1009,10 +1009,10 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1009,10 +1009,10 @@ void CallbackFlushHandler::queue(const int type, const char* data)
// If we have to invalidate all tiles, we can skip any new tile invalidation. // If we have to invalidate all tiles, we can skip any new tile invalidation.
// Find the last INVALIDATE_TILES entry, if any to see if it's invalidate-all. // Find the last INVALIDATE_TILES entry, if any to see if it's invalidate-all.
const auto& pos = std::find_if(m_queue.rbegin(), m_queue.rend(), const auto& pos = std::find_if(m_queue.rbegin(), m_queue.rend(),
[] (const queue_type::value_type& elem) { return (elem.first == LOK_CALLBACK_INVALIDATE_TILES); }); [] (const queue_type::value_type& elem) { return (elem.Type == LOK_CALLBACK_INVALIDATE_TILES); });
if (pos != m_queue.rend()) if (pos != m_queue.rend())
{ {
const RectangleAndPart rcOld = RectangleAndPart::Create(pos->second); const RectangleAndPart rcOld = RectangleAndPart::Create(pos->PayloadString);
if (rcOld.isInfinite() && (rcOld.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart)) if (rcOld.isInfinite() && (rcOld.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart))
{ {
SAL_INFO("lok", "Skipping queue [" << type << "]: [" << payload << "] since all tiles need to be invalidated."); SAL_INFO("lok", "Skipping queue [" << type << "]: [" << payload << "] since all tiles need to be invalidated.");
...@@ -1035,10 +1035,10 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1035,10 +1035,10 @@ void CallbackFlushHandler::queue(const int type, const char* data)
SAL_INFO("lok", "Have Empty [" << type << "]: [" << payload << "] so removing all with part " << rcNew.m_nPart << "."); SAL_INFO("lok", "Have Empty [" << type << "]: [" << payload << "] so removing all with part " << rcNew.m_nPart << ".");
removeAll( removeAll(
[&rcNew] (const queue_type::value_type& elem) { [&rcNew] (const queue_type::value_type& elem) {
if (elem.first == LOK_CALLBACK_INVALIDATE_TILES) if (elem.Type == LOK_CALLBACK_INVALIDATE_TILES)
{ {
// Remove exiting if new is all-encompassing, or if of the same part. // Remove exiting if new is all-encompassing, or if of the same part.
const RectangleAndPart rcOld = RectangleAndPart::Create(elem.second); const RectangleAndPart rcOld = RectangleAndPart::Create(elem.PayloadString);
return (rcNew.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart); return (rcNew.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart);
} }
...@@ -1054,9 +1054,9 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1054,9 +1054,9 @@ void CallbackFlushHandler::queue(const int type, const char* data)
SAL_INFO("lok", "Have [" << type << "]: [" << payload << "] so merging overlapping."); SAL_INFO("lok", "Have [" << type << "]: [" << payload << "] so merging overlapping.");
removeAll( removeAll(
[&rcNew] (const queue_type::value_type& elem) { [&rcNew] (const queue_type::value_type& elem) {
if (elem.first == LOK_CALLBACK_INVALIDATE_TILES) if (elem.Type == LOK_CALLBACK_INVALIDATE_TILES)
{ {
const RectangleAndPart rcOld = RectangleAndPart::Create(elem.second); const RectangleAndPart rcOld = RectangleAndPart::Create(elem.PayloadString);
if (rcNew.m_nPart != -1 && rcOld.m_nPart != -1 && rcOld.m_nPart != rcNew.m_nPart) if (rcNew.m_nPart != -1 && rcOld.m_nPart != -1 && rcOld.m_nPart != rcNew.m_nPart)
{ {
SAL_INFO("lok", "Nothing to merge between new: " << rcNew.toString() << ", and old: " << rcOld.toString()); SAL_INFO("lok", "Nothing to merge between new: " << rcNew.toString() << ", and old: " << rcOld.toString());
...@@ -1129,7 +1129,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1129,7 +1129,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
const std::string name = payload.substr(0, pos + 1); const std::string name = payload.substr(0, pos + 1);
removeAll( removeAll(
[type, &name] (const queue_type::value_type& elem) { [type, &name] (const queue_type::value_type& elem) {
return (elem.first == type) && (elem.second.compare(0, name.size(), name) == 0); return (elem.Type == type) && (elem.PayloadString.compare(0, name.size(), name) == 0);
} }
); );
} }
...@@ -1151,10 +1151,10 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1151,10 +1151,10 @@ void CallbackFlushHandler::queue(const int type, const char* data)
if (aRectStr.empty()) if (aRectStr.empty())
{ {
removeAll([&nLOKWindowId] (const queue_type::value_type& elem) { removeAll([&nLOKWindowId] (const queue_type::value_type& elem) {
if (elem.first == LOK_CALLBACK_WINDOW) if (elem.Type == LOK_CALLBACK_WINDOW)
{ {
boost::property_tree::ptree aOldTree; boost::property_tree::ptree aOldTree;
std::stringstream aOldStream(elem.second); std::stringstream aOldStream(elem.PayloadString);
boost::property_tree::read_json(aOldStream, aOldTree); boost::property_tree::read_json(aOldStream, aOldTree);
const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0); const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0);
if (aOldTree.get<std::string>("action", "") == "invalidate" && if (aOldTree.get<std::string>("action", "") == "invalidate" &&
...@@ -1173,11 +1173,11 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1173,11 +1173,11 @@ void CallbackFlushHandler::queue(const int type, const char* data)
auto invAllExist = std::any_of(m_queue.rbegin(), m_queue.rend(), auto invAllExist = std::any_of(m_queue.rbegin(), m_queue.rend(),
[&nLOKWindowId] (const queue_type::value_type& elem) [&nLOKWindowId] (const queue_type::value_type& elem)
{ {
if (elem.first != LOK_CALLBACK_WINDOW) if (elem.Type != LOK_CALLBACK_WINDOW)
return false; return false;
boost::property_tree::ptree aOldTree; boost::property_tree::ptree aOldTree;
std::stringstream aOldStream(elem.second); std::stringstream aOldStream(elem.PayloadString);
boost::property_tree::read_json(aOldStream, aOldTree); boost::property_tree::read_json(aOldStream, aOldTree);
const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0); const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0);
return aOldTree.get<std::string>("action", "") == "invalidate" && return aOldTree.get<std::string>("action", "") == "invalidate" &&
...@@ -1199,11 +1199,11 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1199,11 +1199,11 @@ void CallbackFlushHandler::queue(const int type, const char* data)
tools::Rectangle aNewRect = tools::Rectangle(nLeft, nTop, nLeft + nWidth, nTop + nHeight); tools::Rectangle aNewRect = tools::Rectangle(nLeft, nTop, nLeft + nWidth, nTop + nHeight);
bool currentIsRedundant = false; bool currentIsRedundant = false;
removeAll([&aNewRect, &nLOKWindowId, &currentIsRedundant] (const queue_type::value_type& elem) { removeAll([&aNewRect, &nLOKWindowId, &currentIsRedundant] (const queue_type::value_type& elem) {
if (elem.first != LOK_CALLBACK_WINDOW) if (elem.Type != LOK_CALLBACK_WINDOW)
return false; return false;
boost::property_tree::ptree aOldTree; boost::property_tree::ptree aOldTree;
std::stringstream aOldStream(elem.second); std::stringstream aOldStream(elem.PayloadString);
boost::property_tree::read_json(aOldStream, aOldTree); boost::property_tree::read_json(aOldStream, aOldTree);
if (aOldTree.get<std::string>("action", "") == "invalidate") if (aOldTree.get<std::string>("action", "") == "invalidate")
{ {
...@@ -1287,8 +1287,8 @@ void CallbackFlushHandler::Invoke() ...@@ -1287,8 +1287,8 @@ void CallbackFlushHandler::Invoke()
SAL_INFO("lok", "Flushing " << m_queue.size() << " elements."); SAL_INFO("lok", "Flushing " << m_queue.size() << " elements.");
for (auto& pair : m_queue) for (auto& pair : m_queue)
{ {
const int type = pair.first; const int type = pair.Type;
const auto& payload = pair.second; const auto& payload = pair.PayloadString;
const int viewId = lcl_isViewCallbackType(type) ? lcl_getViewId(payload) : -1; const int viewId = lcl_isViewCallbackType(type) ? lcl_getViewId(payload) : -1;
if (viewId == -1) if (viewId == -1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment