loolwsd: use more efficient matchPrefix

Change-Id: I6f34b314295335270ff4da2827517d818c6a62ab
Reviewed-on: https://gerrit.libreoffice.org/31285
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
Ashod Nakashian 2016-11-26 22:24:35 -05:00 committed by Ashod Nakashian
parent 86b38a29de
commit a8f3263132
2 changed files with 6 additions and 6 deletions

View file

@ -152,7 +152,7 @@ void TileQueue::put_impl(const Payload& value)
void TileQueue::removeDuplicate(const std::string& tileMsg)
{
assert(LOOLProtocol::getFirstToken(tileMsg) == "tile");
assert(LOOLProtocol::matchPrefix("tile", tileMsg, /*ignoreWhitespace*/ true));
// Ver is always provided at this point and it is necessary to
// return back to clients the last rendered version of a tile
@ -200,7 +200,7 @@ void TileQueue::deprioritizePreviews()
// stop at the first non-tile or non-'id' (preview) message
std::string id;
if (LOOLProtocol::getFirstToken(message) != "tile" ||
if (!LOOLProtocol::matchPrefix("tile", message) ||
!LOOLProtocol::getTokenStringFromMessage(message, "id", id))
{
break;
@ -218,7 +218,7 @@ MessageQueue::Payload TileQueue::get_impl()
auto msg = std::string(front.data(), front.size());
std::string id;
bool isTile = (LOOLProtocol::getFirstToken(msg) == "tile");
bool isTile = LOOLProtocol::matchPrefix("tile", msg);
bool isPreview = isTile && LOOLProtocol::getTokenStringFromMessage(msg, "id", id);
if (!isTile || isPreview)
{
@ -246,7 +246,7 @@ MessageQueue::Payload TileQueue::get_impl()
// avoid starving - stop the search when we reach a non-tile,
// otherwise we may keep growing the queue of unhandled stuff (both
// tiles and non-tiles)
if (LOOLProtocol::getFirstToken(prio) != "tile" ||
if (!LOOLProtocol::matchPrefix("tile", prio) ||
LOOLProtocol::getTokenStringFromMessage(prio, "id", id))
{
break;
@ -277,7 +277,7 @@ MessageQueue::Payload TileQueue::get_impl()
{
auto& it = _queue[i];
msg = std::string(it.data(), it.size());
if (LOOLProtocol::getFirstToken(msg) != "tile" ||
if (!LOOLProtocol::matchPrefix("tile", msg) ||
LOOLProtocol::getTokenStringFromMessage(msg, "id", id))
{
// Don't combine non-tiles or tiles with id.

View file

@ -324,7 +324,7 @@ bool isDocumentLoaded(LOOLWebSocket& ws, const std::string& name = "", bool isVi
{
const std::string prefix = isView ? "status:" : "statusindicatorfinish:";
const auto message = getResponseString(ws, prefix, name);
return LOOLProtocol::getFirstToken(message) == prefix;
return LOOLProtocol::matchPrefix(prefix, message);
}
inline