mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-04 05:51:31 +00:00
slightly more efficient line conversion
This commit is contained in:
@ -29,7 +29,7 @@ struct TextInputStream<InStream: InputStream> where InStream.Element == UInt8 {
|
|||||||
|
|
||||||
private var _stream: InStream
|
private var _stream: InStream
|
||||||
private var _utf8Decoder = UTF8()
|
private var _utf8Decoder = UTF8()
|
||||||
private var _scalars = [Unicode.Scalar]()
|
private var _string = String()
|
||||||
private var _lastChar: UnicodeScalar = "\0"
|
private var _lastChar: UnicodeScalar = "\0"
|
||||||
private var _eof = false
|
private var _eof = false
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ struct TextInputStream<InStream: InputStream> where InStream.Element == UInt8 {
|
|||||||
} else if value == "\r" {
|
} else if value == "\r" {
|
||||||
break Decode
|
break Decode
|
||||||
}
|
}
|
||||||
self._scalars.append(value)
|
self._string.unicodeScalars.append(value)
|
||||||
self._lastChar = value
|
self._lastChar = value
|
||||||
case .emptyInput:
|
case .emptyInput:
|
||||||
self._eof = true
|
self._eof = true
|
||||||
@ -66,18 +66,15 @@ struct TextInputStream<InStream: InputStream> where InStream.Element == UInt8 {
|
|||||||
// Decode a line of scalars
|
// Decode a line of scalars
|
||||||
self.decodeScalarsLine()
|
self.decodeScalarsLine()
|
||||||
defer {
|
defer {
|
||||||
self._scalars.removeAll(keepingCapacity: true)
|
self._string.removeAll(keepingCapacity: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore the final empty newline
|
// Ignore the final empty newline
|
||||||
guard !self._eof || !self._scalars.isEmpty else {
|
guard !self._eof || !self._string.isEmpty else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to string and return
|
return self._string
|
||||||
var string = String()
|
|
||||||
string.unicodeScalars.append(contentsOf: self._scalars)
|
|
||||||
return string
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user