             // We use & 0x1f to make the compiler omit a bounds check branch.
             _decodeBuffer |= (UInt32(codeUnit) << UInt32(_bitsInBuffer & 0x1f))
             _bitsInBuffer = _bitsInBuffer &+ 8
-          } else { // Exhausted generator.
-            _atEnd = true
+          } else {
+            _didExhaustGenerator = true
             if _bitsInBuffer == 0 { return .EmptyInput }
             break // We still have some bytes left in our buffer.
           }

              _decodeBuffer = UInt32(codeUnit)
              _bitsInBuffer = 8
            }
          } else { // Exhausted generator.
            _atEnd = true
            return .EmptyInput
          }
        } else if(_decodeBuffer & 0x80 == 0) {

    G : GeneratorType where G.Element == CodeUnit
    >(next: inout G) -> UnicodeDecodingResult {

      refillBuffer: if !_didExhaustGenerator {
        // Bufferless ASCII fastpath.
        if _fastPath(_bitsInBuffer == 0) {
          if let codeUnit = next.next() {
