KitQueue - remove more un-necessary code, and helper use.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ic11db8ac1391bd22b4adcae40c99fa4ca99790f1
pull/8165/merge
Michael Meeks 2024-05-08 19:47:25 +01:00 committed by Caolán McNamara
parent 70ff910f20
commit 320606c225
3 changed files with 50 additions and 58 deletions

View File

@ -97,14 +97,14 @@ void KitQueue::removeTileDuplicate(const std::string& tileMsg)
newMsgPos = tileMsg.size() - 1;
}
for (size_t i = 0; i < getQueue().size(); ++i)
for (size_t i = 0; i < _queue.size(); ++i)
{
auto& it = getQueue()[i];
auto& it = _queue[i];
if (it.size() > newMsgPos &&
strncmp(tileMsg.data(), it.data(), newMsgPos) == 0)
{
LOG_TRC("Remove duplicate tile request: " << std::string(it.data(), it.size()) << " -> " << COOLProtocol::getAbbreviatedMessage(tileMsg));
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
break;
}
}
@ -259,9 +259,9 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
// we always travel the entire queue
std::size_t i = 0;
while (i < getQueue().size())
while (i < _queue.size())
{
auto& it = getQueue()[i];
auto& it = _queue[i];
StringVector queuedTokens = StringVector::tokenize(it.data(), it.size());
if (queuedTokens.size() < 3)
@ -309,7 +309,7 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
<< msgW << ' ' << msgH << ' ' << msgPart << ' ' << msgMode);
// remove from the queue
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
continue;
}
@ -347,7 +347,7 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
performedMerge = true;
// remove from the queue
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
continue;
}
@ -385,14 +385,14 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
if (unoCommand == ".uno:ModifiedStatus")
return std::string();
if (getQueue().empty())
if (_queue.empty())
return std::string();
// remove obsolete states of the same .uno: command
isDuplicateCommand functor(unoCommand, tokens);
for (std::size_t i = 0; i < getQueue().size(); ++i)
for (std::size_t i = 0; i < _queue.size(); ++i)
{
auto& it = getQueue()[i];
auto& it = _queue[i];
StringVector::tokenize_foreach(functor, it.data(), it.size());
@ -401,7 +401,7 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
LOG_TRC("Remove obsolete uno command: "
<< std::string(it.data(), it.size()) << " -> "
<< COOLProtocol::getAbbreviatedMessage(callbackMsg));
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
break;
}
functor.reset();
@ -425,9 +425,9 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
const std::string viewId
= (isViewCallback ? extractViewId(callbackMsg, tokens) : std::string());
for (std::size_t i = 0; i < getQueue().size(); ++i)
for (std::size_t i = 0; i < _queue.size(); ++i)
{
const auto& it = getQueue()[i];
const auto& it = _queue[i];
// skip non-callbacks quickly
if (!COOLProtocol::matchPrefix("callback", it))
@ -443,7 +443,7 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
LOG_TRC("Remove obsolete callback: "
<< std::string(it.data(), it.size()) << " -> "
<< COOLProtocol::getAbbreviatedMessage(callbackMsg));
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
break;
}
else if (isViewCallback
@ -461,7 +461,7 @@ std::string KitQueue::removeCallbackDuplicate(const std::string& callbackMsg)
LOG_TRC("Remove obsolete view callback: "
<< std::string(it.data(), it.size()) << " -> "
<< COOLProtocol::getAbbreviatedMessage(callbackMsg));
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
break;
}
}
@ -494,9 +494,9 @@ int KitQueue::priority(const std::string& tileMsg)
void KitQueue::deprioritizePreviews()
{
for (size_t i = 0; i < getQueue().size(); ++i)
for (size_t i = 0; i < _queue.size(); ++i)
{
const Payload front = getQueue().front();
const Payload front = _queue.front();
const std::string message(front.data(), front.size());
// stop at the first non-tile or non-'id' (preview) message
@ -507,16 +507,16 @@ void KitQueue::deprioritizePreviews()
break;
}
getQueue().erase(getQueue().begin());
getQueue().push_back(front);
_queue.erase(_queue.begin());
_queue.push_back(front);
}
}
KitQueue::Payload KitQueue::get()
{
LOG_TRC("KitQueue depth: " << getQueue().size());
LOG_TRC("KitQueue depth: " << _queue.size());
const Payload front = getQueue().front();
const Payload front = _queue.front();
std::string msg(front.data(), front.size());
@ -527,7 +527,7 @@ KitQueue::Payload KitQueue::get()
{
// Don't combine non-tiles or tiles with id.
LOG_TRC("KitQueue res: " << COOLProtocol::getAbbreviatedMessage(msg));
getQueue().erase(getQueue().begin());
_queue.erase(_queue.begin());
// de-prioritize the other tiles with id - usually the previews in
// Impress
@ -541,9 +541,9 @@ KitQueue::Payload KitQueue::get()
// position, otherwise handle the one that is at the front
int prioritized = 0;
int prioritySoFar = -1;
for (size_t i = 0; i < getQueue().size(); ++i)
for (size_t i = 0; i < _queue.size(); ++i)
{
auto& it = getQueue()[i];
auto& it = _queue[i];
const std::string prio(it.data(), it.size());
// avoid starving - stop the search when we reach a non-tile,
@ -570,15 +570,15 @@ KitQueue::Payload KitQueue::get()
}
}
getQueue().erase(getQueue().begin() + prioritized);
_queue.erase(_queue.begin() + prioritized);
std::vector<TileDesc> tiles;
tiles.emplace_back(TileDesc::parse(msg));
// Combine as many tiles as possible with the top one.
for (size_t i = 0; i < getQueue().size(); )
for (size_t i = 0; i < _queue.size(); )
{
auto& it = getQueue()[i];
auto& it = _queue[i];
msg = std::string(it.data(), it.size());
if (!COOLProtocol::matchPrefix("tile", msg) ||
COOLProtocol::getTokenStringFromMessage(msg, "id", id))
@ -595,7 +595,7 @@ KitQueue::Payload KitQueue::get()
if (tiles[0].canCombine(tile2))
{
tiles.emplace_back(tile2);
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
}
else
{
@ -603,7 +603,7 @@ KitQueue::Payload KitQueue::get()
}
}
LOG_TRC("Combined " << tiles.size() << " tiles, leaving " << getQueue().size() << " in queue.");
LOG_TRC("Combined " << tiles.size() << " tiles, leaving " << _queue.size() << " in queue.");
if (tiles.size() == 1)
{
@ -653,10 +653,10 @@ std::string KitQueue::combineTextInput(const StringVector& tokens)
!COOLProtocol::getTokenString(tokens, "text", text))
return std::string();
int i = getQueue().size() - 1;
int i = _queue.size() - 1;
while (i >= 0)
{
auto& it = getQueue()[i];
auto& it = _queue[i];
const std::string queuedMessage(it.data(), it.size());
StringVector queuedTokens = StringVector::tokenize(it.data(), it.size());
@ -680,7 +680,7 @@ std::string KitQueue::combineTextInput(const StringVector& tokens)
COOLProtocol::getTokenString(queuedTokens, "text", queuedText))
{
// Remove the queued textinput message and combine it with the current one
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
std::string newMsg;
newMsg.reserve(it.size() * 2);
@ -713,10 +713,10 @@ std::string KitQueue::combineRemoveText(const StringVector& tokens)
!COOLProtocol::getTokenInteger(tokens, "after", after))
return std::string();
int i = getQueue().size() - 1;
int i = _queue.size() - 1;
while (i >= 0)
{
auto& it = getQueue()[i];
auto& it = _queue[i];
const std::string queuedMessage(it.data(), it.size());
StringVector queuedTokens = StringVector::tokenize(it.data(), it.size());
@ -742,7 +742,7 @@ std::string KitQueue::combineRemoveText(const StringVector& tokens)
COOLProtocol::getTokenIntegerFromMessage(queuedMessage, "after", queuedAfter))
{
// Remove the queued removetextcontext message and combine it with the current one
getQueue().erase(getQueue().begin() + i);
_queue.erase(_queue.begin() + i);
std::string newMsg = queuedTokens[0] + " removetextcontext id=" + id +
" before=" + std::to_string(queuedBefore + before) +

View File

@ -29,14 +29,8 @@ class KitQueue
public:
typedef std::vector<char> Payload;
KitQueue()
{
}
~KitQueue()
{
clear();
}
KitQueue() { }
~KitQueue() { }
KitQueue(const KitQueue&) = delete;
KitQueue& operator=(const KitQueue&) = delete;
@ -81,8 +75,6 @@ public:
void dumpState(std::ostream& oss);
protected:
std::vector<Payload>& getQueue() { return _queue; }
/// Search the queue for a previous textinput message and if found, remove it and combine its
/// input with that in the current textinput message. We check that there aren't any interesting
/// messages inbetween that would make it wrong to merge the textinput messages.
@ -153,7 +145,7 @@ private:
int priority(const std::string& tileMsg);
private:
/// The underlying queue
/// The incoming underlying queue
std::vector<Payload> _queue;
std::map<int, CursorPosition> _cursorPositions;

View File

@ -150,7 +150,7 @@ void KitQueueTests::testTileRecombining()
queue.put("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840");
// the tilecombine's get merged, resulting in 3 "tile" messages
LOK_ASSERT_EQUAL(3, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(3, static_cast<int>(queue.size()));
// but when we later extract that, it is just one "tilecombine" message
LOK_ASSERT_EQUAL_STR(
@ -159,7 +159,7 @@ void KitQueueTests::testTileRecombining()
queue.get());
// and nothing remains in the queue
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.size()));
}
void KitQueueTests::testViewOrder()
@ -187,7 +187,7 @@ void KitQueueTests::testViewOrder()
for (auto &tile : tiles)
queue.put(tile);
LOK_ASSERT_EQUAL(4, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(4, static_cast<int>(queue.size()));
// should result in the 3, 2, 1, 0 order of the tiles thanks to the cursor
// positions
@ -221,7 +221,7 @@ void KitQueueTests::testPreviewsDeprioritization()
}
// stays empty after all is done
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.size()));
// re-ordering case - put previews and normal tiles to the queue and get
// everything back again but this time the tiles have to interleave with
@ -248,7 +248,7 @@ void KitQueueTests::testPreviewsDeprioritization()
LOK_ASSERT_EQUAL_STR(previews[3], queue.get());
// stays empty after all is done
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.size()));
// cursor positioning case - the cursor position should not prioritize the
// previews
@ -261,7 +261,7 @@ void KitQueueTests::testPreviewsDeprioritization()
LOK_ASSERT_EQUAL_STR(previews[0], queue.get());
// stays empty after all is done
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.size()));
}
namespace {
@ -480,7 +480,7 @@ void KitQueueTests::testCallbackInvalidation()
queue.put("callback all 0 284, 1418, 11105, 275, 0");
queue.put("callback all 0 4299, 1418, 7090, 275, 0");
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.size()));
LOK_ASSERT_EQUAL_STR("callback all 0 284, 1418, 11105, 275, 0", queue.get());
@ -490,11 +490,11 @@ void KitQueueTests::testCallbackInvalidation()
queue.put("callback all 0 4299, 10418, 7090, 275, 0");
queue.put("callback all 0 4299, 20418, 7090, 275, 0");
LOK_ASSERT_EQUAL(4, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(4, static_cast<int>(queue.size()));
queue.put("callback all 0 EMPTY, 0");
LOK_ASSERT_EQUAL(2, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(2, static_cast<int>(queue.size()));
LOK_ASSERT_EQUAL_STR("callback all 0 4299, 1418, 7090, 275, 1", queue.get());
LOK_ASSERT_EQUAL_STR("callback all 0 EMPTY, 0", queue.get());
}
@ -509,7 +509,7 @@ void KitQueueTests::testCallbackIndicatorValue()
queue.put("callback all 10 25");
queue.put("callback all 10 50");
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.size()));
LOK_ASSERT_EQUAL_STR("callback all 10 50", queue.get());
}
@ -523,7 +523,7 @@ void KitQueueTests::testCallbackPageSize()
queue.put("callback all 13 12474, 188626");
queue.put("callback all 13 12474, 205748");
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.size()));
LOK_ASSERT_EQUAL_STR("callback all 13 12474, 205748", queue.get());
}
@ -548,7 +548,7 @@ void KitQueueTests::testCallbackModifiedStatusIsSkipped()
queue.put(msg);
}
LOK_ASSERT_EQUAL(static_cast<size_t>(4), queue.getQueue().size());
LOK_ASSERT_EQUAL(static_cast<size_t>(4), queue.size());
LOK_ASSERT_EQUAL_STR(messages[0], queue.get());
LOK_ASSERT_EQUAL_STR(messages[1], queue.get());