From 726379c5811dac450f92975db58be71ff031eafd Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 13 May 2024 16:29:46 -0700 Subject: [PATCH] QByteArrayView: move up the call to 1-char findByteArray() The public, inline QtPrivate::findByteArray() function duplicates some of the entry conditions that this does (including the negative from), so help the compilers. Task-number: QTBUG-125283 Change-Id: If05cb740b64f42eba21efffd17cf3034ce9ab9b8 Reviewed-by: Ahmad Samir --- src/corelib/text/qbytearraymatcher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qbytearraymatcher.cpp b/src/corelib/text/qbytearraymatcher.cpp index b3e38d53e4..67cf355ddf 100644 --- a/src/corelib/text/qbytearraymatcher.cpp +++ b/src/corelib/text/qbytearraymatcher.cpp @@ -243,6 +243,9 @@ qsizetype QtPrivate::findByteArray(QByteArrayView haystack, qsizetype from, QByt const auto haystack0 = haystack.data(); const auto l = haystack.size(); const auto sl = needle.size(); + if (sl == 1) + return findByteArray(haystack, from, needle.front()); + if (from < 0) from += l; if (std::size_t(sl + from) > std::size_t(l)) @@ -252,9 +255,6 @@ qsizetype QtPrivate::findByteArray(QByteArrayView haystack, qsizetype from, QByt if (!l) return -1; - if (sl == 1) - return findByteArray(haystack, from, needle.front()); - /* We use the Boyer-Moore algorithm in cases where the overhead for the skip table should pay off, otherwise we use a simple