Bug 1305422 - part 5 - simplify Is8bit; r=baku
authorNathan Froyd <froydnj@mozilla.com>
Thu, 29 Sep 2016 22:33:58 -0400
changeset 315875 1c06cb170aa873c9ee4e18f111a600752eba6c22
parent 315874 a5b04e48b3e8e70b8a213afb75170da85c4d5b62
child 315876 9b814ee26cd7a8d4eeb1f9e3206a4e6b37d22b2a
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1305422
milestone52.0a1
Bug 1305422 - part 5 - simplify Is8bit; r=baku The implementation of Is8bit, with its multiply-nested loops, dates from the time when string iterators could be fragmented into multiple pieces. We no longer have such iterators, so we can write Is8bit much more straightforwardly, with the single loop you would expect.
dom/base/nsContentUtils.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -787,33 +787,22 @@ nsContentUtils::InitializeTouchEventTabl
   }
 }
 
 static bool
 Is8bit(const nsAString& aString)
 {
   static const char16_t EIGHT_BIT = char16_t(~0x00FF);
 
-  nsAString::const_iterator done_reading;
-  aString.EndReading(done_reading);
-
-  // for each chunk of |aString|...
-  uint32_t fragmentLength = 0;
-  nsAString::const_iterator iter;
-  for (aString.BeginReading(iter); iter != done_reading;
-       iter.advance(int32_t(fragmentLength))) {
-    fragmentLength = uint32_t(iter.size_forward());
-    const char16_t* c = iter.get();
-    const char16_t* fragmentEnd = c + fragmentLength;
-
-    // for each character in this chunk...
-    while (c < fragmentEnd) {
-      if (*c++ & EIGHT_BIT) {
-        return false;
-      }
+  for (nsAString::const_char_iterator start = aString.BeginReading(),
+         end = aString.EndReading();
+       start != end;
+       ++start) {
+    if (*start & EIGHT_BIT) {
+      return false;
     }
   }
 
   return true;
 }
 
 nsresult
 nsContentUtils::Btoa(const nsAString& aBinaryData,