     I : IteratorProtocol where I.Element == CodeUnit
   >(next: inout I) -> UnicodeDecodingResult {
 
-      refillBuffer: if !_didExhaustIterator {
-        // Bufferless ASCII fastpath.
-        if _fastPath(_bitsInBuffer == 0) {
-          if let codeUnit = next.next() {
-            if codeUnit & 0x80 == 0 {
-              return .scalarValue(UnicodeScalar(_unchecked: UInt32(codeUnit)))
-            }
-            // Non-ASCII, proceed to buffering mode.
-            _decodeBuffer = UInt32(codeUnit)
-            _bitsInBuffer = 8
-          } else {
-            _didExhaustIterator = true
-            return .emptyInput
+    refillBuffer: if !_didExhaustIterator {
+      // Bufferless ASCII fastpath.
+      if _fastPath(_bitsInBuffer == 0) {
+        if let codeUnit = next.next() {
+          if codeUnit & 0x80 == 0 {
+            return .scalarValue(UnicodeScalar(_unchecked: UInt32(codeUnit)))
           }
-        } else if(_decodeBuffer & 0x80 == 0) {
-          // ASCII in buffer.  We don't refill the buffer so we can return
-          // to bufferless mode once we've exhausted it.
-          break refillBuffer
+          // Non-ASCII, proceed to buffering mode.
+          _decodeBuffer = UInt32(codeUnit)
+          _bitsInBuffer = 8
+        } else {
+          _didExhaustIterator = true
+          return .emptyInput
         }
-        // Buffering mode.
-        // Fill buffer back to 4 bytes (or as many as are left in the iterator).
-        _sanityCheck(_bitsInBuffer < 32)
-        repeat {
-          if let codeUnit = next.next() {
-            // We use & 0x1f to make the compiler omit a bounds check branch.
-            _decodeBuffer |= (UInt32(codeUnit) << UInt32(_bitsInBuffer & 0x1f))
-            _bitsInBuffer = _bitsInBuffer &+ 8
-          } else {
-            _didExhaustIterator = true
-            if _bitsInBuffer == 0 { return .emptyInput }
-            break // We still have some bytes left in our buffer.
-          }
-        } while _bitsInBuffer < 32
-      } else if _bitsInBuffer == 0 {
-        return .emptyInput
-      }
-
-      // Decode one unicode scalar.
-      // Note our empty bytes are always 0x00, which is required for this call.
-      let (result, length) = UTF8._decodeOne(_decodeBuffer)
-
-      // Consume the decoded bytes (or maximal subpart of ill-formed sequence).
-      let bitsConsumed = 8 &* length
-      _sanityCheck(1...4 ~= length && bitsConsumed <= _bitsInBuffer)
-      // Swift doesn't allow shifts greater than or equal to the type width.
-      // _decodeBuffer >>= UInt32(bitsConsumed) // >>= 32 crashes.
-      // Mask with 0x3f to let the compiler omit the '>= 64' bounds check.
-      _decodeBuffer = UInt32(truncatingBitPattern:
-        UInt64(_decodeBuffer) >> (UInt64(bitsConsumed) & 0x3f))
-      _bitsInBuffer = _bitsInBuffer &- bitsConsumed
-
-      if _fastPath(result != nil) {
-        return .scalarValue(UnicodeScalar(_unchecked: result!))
-      } else {
-        return .error // Ill-formed UTF-8 code unit sequence.
-      }
+      } else if(_decodeBuffer & 0x80 == 0) {
+        // ASCII in buffer.  We don't refill the buffer so we can return
+        // to bufferless mode once we've exhausted it.
+        break refillBuffer
+      }
+      // Buffering mode.
+      // Fill buffer back to 4 bytes (or as many as are left in the iterator).
+      _sanityCheck(_bitsInBuffer < 32)
+      repeat {
+        if let codeUnit = next.next() {
+          // We use & 0x1f to make the compiler omit a bounds check branch.
+          _decodeBuffer |= (UInt32(codeUnit) << UInt32(_bitsInBuffer & 0x1f))
+          _bitsInBuffer = _bitsInBuffer &+ 8
+        } else {
+          _didExhaustIterator = true
+          if _bitsInBuffer == 0 { return .emptyInput }
+          break // We still have some bytes left in our buffer.
+        }
+      } while _bitsInBuffer < 32
+    } else if _bitsInBuffer == 0 {
+      return .emptyInput
+    }
+
+    // Decode one unicode scalar.
+    // Note our empty bytes are always 0x00, which is required for this call.
+    let (result, length) = UTF8._decodeOne(_decodeBuffer)
+
+    // Consume the decoded bytes (or maximal subpart of ill-formed sequence).
+    let bitsConsumed = 8 &* length
+    _sanityCheck(1...4 ~= length && bitsConsumed <= _bitsInBuffer)
+    // Swift doesn't allow shifts greater than or equal to the type width.
+    // _decodeBuffer >>= UInt32(bitsConsumed) // >>= 32 crashes.
+    // Mask with 0x3f to let the compiler omit the '>= 64' bounds check.
+    _decodeBuffer = UInt32(truncatingBitPattern:
+      UInt64(_decodeBuffer) >> (UInt64(bitsConsumed) & 0x3f))
+    _bitsInBuffer = _bitsInBuffer &- bitsConsumed
+
+    if _fastPath(result != nil) {
+      return .scalarValue(UnicodeScalar(_unchecked: result!))
+    } else {
+      return .error // Ill-formed UTF-8 code unit sequence.
+    }
   }
 
   /// Attempts to decode a single UTF-8 code unit sequence starting at the LSB

    _precondition(width(x) == 2)
    return UTF16.CodeUnit(
      (x.value - 0x1_0000) & (((1 as UInt32) << 10) - 1)
      ) + 0xDC00
  }

  @warn_unused_result

  public static func transcodedLength<
    Encoding : UnicodeCodec, Input : IteratorProtocol
    where Encoding.CodeUnit == Input.Element
  >(
    of input: Input,
    decodedAs sourceEncoding: Encoding.Type,
    repairingIllFormedSequences: Bool
  ) -> (count: Int, isASCII: Bool)? {
    var input = input
    var count = 0
    var isAscii = true

    var inputDecoder = Encoding()
    loop:
    while true {
      switch inputDecoder.decode(&input) {
      case .scalarValue(let us):
        if us.value > 0x7f {
          isAscii = false
        }
        count += width(us)
      case .emptyInput:
        break loop
      case .error:
        if !repairingIllFormedSequences {
          return nil
        }
        isAscii = false
        count += width(UnicodeScalar(0xfffd))
      }
    }
    return (count, isAscii)
  }
}

