Bug 1500053 - Fix missed optimization in autocomplete_match helpers. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 20 Oct 2018 10:03:42 +0000
changeset 490584 a2df0d50925f188b41fdc60328b058b4afb53a41
parent 490583 08ca28f32dcd7c69277a8f0d393f6f435860eae4
child 490585 5d4fb7fef7d0383e4244bdd221ec61018bff1662
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersadw
bugs1500053
milestone64.0a1
Bug 1500053 - Fix missed optimization in autocomplete_match helpers. r=adw Differential Revision: https://phabricator.services.mozilla.com/D9316
toolkit/components/places/SQLFunctions.cpp
--- a/toolkit/components/places/SQLFunctions.cpp
+++ b/toolkit/components/places/SQLFunctions.cpp
@@ -37,30 +37,26 @@ namespace {
 
   /**
    * Scan forward through UTF-8 text until the next potential character that
    * could match a given codepoint when lower-cased (false positives are okay).
    * This avoids having to actually parse the UTF-8 text, which is slow.
    *
    * @param aStart
    *        An iterator pointing to the first character position considered.
+   *        It will be updated by this function.
    * @param aEnd
    *        An interator pointing to past-the-end of the string.
-   *
-   * @return An iterator pointing to the first potential matching character
-   *         within the range [aStart, aEnd).
    */
   static
-  MOZ_ALWAYS_INLINE const_char_iterator
-  nextSearchCandidate(const_char_iterator aStart,
-                      const_char_iterator aEnd,
-                      uint32_t aSearchFor)
+  MOZ_ALWAYS_INLINE void
+  goToNextSearchCandidate(const_char_iterator& aStart,
+                          const const_char_iterator& aEnd,
+                          uint32_t aSearchFor)
   {
-    const_char_iterator cur = aStart;
-
     // If the character we search for is ASCII, then we can scan until we find
     // it or its ASCII uppercase character, modulo the special cases
     // U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE and U+212A KELVIN SIGN
     // (which are the only non-ASCII characters that lower-case to ASCII ones).
     // Since false positives are okay, we approximate ASCII lower-casing by
     // bit-ORing with 0x20, for increased performance.
     //
     // If the character we search for is *not* ASCII, we can ignore everything
@@ -77,28 +73,25 @@ namespace {
       // in the loop below.  For other characters we fall back to 0xff, which
       // is not a valid UTF-8 byte.
       unsigned char target = (unsigned char)(aSearchFor | 0x20);
       unsigned char special = 0xff;
       if (target == 'i' || target == 'k') {
         special = (target == 'i' ? 0xc4 : 0xe2);
       }
 
-      while (cur < aEnd && (unsigned char)(*cur | 0x20) != target &&
-          (unsigned char)*cur != special) {
-        cur++;
+      while (aStart < aEnd && (unsigned char)(*aStart | 0x20) != target &&
+          (unsigned char)*aStart != special) {
+        aStart++;
       }
     } else {
-      const_char_iterator cur = aStart;
-      while (cur < aEnd && (unsigned char)(*cur) < 128) {
-        cur++;
+      while (aStart < aEnd && (unsigned char)(*aStart) < 128) {
+        aStart++;
       }
     }
-
-    return cur;
   }
 
   /**
    * Check whether a character position is on a word boundary of a UTF-8 string
    * (rather than within a word).  We define "within word" to be any position
    * between [a-zA-Z] and [a-z] -- this lets us match CamelCase words.
    * TODO: support non-latin alphabets.
    *
@@ -205,17 +198,17 @@ namespace {
     uint32_t tokenFirstChar =
       GetLowerUTF8Codepoint(tokenStart, tokenEnd, &tokenNext);
     if (tokenFirstChar == uint32_t(-1)) {
       return false;
     }
 
     for (;;) {
       // Scan forward to the next viable candidate (if any).
-      sourceCur = nextSearchCandidate(sourceCur, sourceEnd, tokenFirstChar);
+      goToNextSearchCandidate(sourceCur, sourceEnd, tokenFirstChar);
       if (sourceCur == sourceEnd) {
         break;
       }
 
       // Check whether the first character in the token matches the character
       // at sourceCur.  At the same time, get a pointer to the next character
       // in the source.
       uint32_t sourceFirstChar =