Skip to content

Commit 4570c7f

Browse files
committed
---
yaml --- r: 346097 b: refs/heads/master c: fbad0b2 h: refs/heads/master i: 346095: a1de698
1 parent 38ca63b commit 4570c7f

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2096fd21ebdef9f5dd7f754413b9bca2f73728b4
2+
refs/heads/master: fbad0b286af850d1f058ad3bda8a5380fce34058
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/stdlib/public/core/StringCharacterView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ extension String {
234234

235235
@inlinable
236236
internal init(_ guts: _StringGuts) {
237-
self._guts = guts
238237
self._end = guts.count
238+
self._guts = guts
239239
}
240240

241241
@inlinable

trunk/stdlib/public/core/StringUTF16View.swift

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,59 @@ extension String.UTF16View: BidirectionalCollection {
260260
}
261261
}
262262
}
263+
264+
extension String.UTF16View {
265+
@_fixed_layout
266+
public struct Iterator: IteratorProtocol {
267+
@usableFromInline
268+
internal var _guts: _StringGuts
269+
270+
@usableFromInline
271+
internal var _position: Int = 0
272+
273+
@usableFromInline
274+
internal var _end: Int
275+
276+
// If non-nil, return this value for `next()` (and set it to nil).
277+
//
278+
// This is set when visiting a non-BMP scalar: the leading surrogate is
279+
// returned, this field is set with the value of the trailing surrogate, and
280+
// `_position` is advanced to the start of the next scalar.
281+
@usableFromInline
282+
internal var _nextIsTrailingSurrogate: UInt16? = nil
283+
284+
@inlinable
285+
internal init(_ guts: _StringGuts) {
286+
self._end = guts.count
287+
self._guts = guts
288+
}
289+
290+
@inlinable
291+
public mutating func next() -> UInt16? {
292+
if _slowPath(_nextIsTrailingSurrogate != nil) {
293+
let trailing = self._nextIsTrailingSurrogate._unsafelyUnwrappedUnchecked
294+
self._nextIsTrailingSurrogate = nil
295+
return trailing
296+
}
297+
guard _fastPath(_position < _end) else { return nil }
298+
299+
let (scalar, len) = _guts.errorCorrectedScalar(startingAt: _position)
300+
_position &+= len
301+
302+
if _slowPath(scalar.value > UInt16.max) {
303+
self._nextIsTrailingSurrogate = scalar.utf16[1]
304+
return scalar.utf16[0]
305+
}
306+
return UInt16(truncatingIfNeeded: scalar.value)
307+
}
308+
}
309+
@inlinable
310+
public __consuming func makeIterator() -> Iterator {
311+
return Iterator(_guts)
312+
}
313+
}
314+
315+
263316
extension String.UTF16View: CustomStringConvertible {
264317
@inlinable
265318
public var description: String {
@@ -464,7 +517,7 @@ extension String.UTF16View {
464517
if idx.encodedOffset < _shortHeuristic || !_guts.hasBreadcrumbs {
465518
return _distance(from: startIndex, to: idx)
466519
}
467-
520+
468521
// Simple and common: endIndex aka `length`.
469522
let breadcrumbsPtr = _guts.getBreadcrumbsPtr()
470523
if idx == endIndex { return breadcrumbsPtr.pointee.utf16Length }

trunk/stdlib/public/core/StringUnicodeScalarView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ extension String.UnicodeScalarView {
180180

181181
@inlinable
182182
internal init(_ guts: _StringGuts) {
183-
self._guts = guts
184183
self._end = guts.count
184+
self._guts = guts
185185
}
186186

187187
@inlinable

trunk/test/api-digester/Outputs/stability-stdlib-abi.swift.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ Var _StringGutsSlice.isNFCFastUTF8 has been removed
499499
Var _StringGutsSlice.range has been removed
500500
Var _StringGutsSlice.start has been removed
501501

502+
Struct String.UTF16View has type witness type for Collection.Iterator changing from IndexingIterator<String.UTF16View> to String.UTF16View.Iterator
503+
Struct String.UTF16View has type witness type for Sequence.Iterator changing from IndexingIterator<String.UTF16View> to String.UTF16View.Iterator
504+
502505
Func ManagedBufferPointer._sanityCheckValidBufferClass(_:creating:) has been removed
503506
Func _sanityCheck(_:_:file:line:) has been removed
504507
Func _sanityCheckFailure(_:file:line:) has been removed

0 commit comments

Comments
 (0)