@@ -21,8 +21,9 @@ extension RangeReplaceableCollection {
21
21
/// - parameter cursor: The cursor whose elements feed the collection.
22
22
public init < C: Cursor > ( _ cursor: C ) throws where C. Element == Element {
23
23
self . init ( )
24
- // Use `forEach` in order to deal with <https://github.com/groue/GRDB.swift/issues/1124>.
25
- // See `Statement.forEachStep(_:)` for more information.
24
+ // Prefer `forEach` over `next()` looping, as a slight performance
25
+ // improvement due to the single `sqlite3_stmt_busy` check for
26
+ // database cursors.
26
27
try cursor. forEach { append ( $0) }
27
28
}
28
29
@@ -38,6 +39,9 @@ extension RangeReplaceableCollection {
38
39
public init < C: Cursor > ( _ cursor: C , minimumCapacity: Int ) throws where C. Element == Element {
39
40
self . init ( )
40
41
reserveCapacity ( minimumCapacity)
42
+ // Prefer `forEach` over `next()` looping, as a slight performance
43
+ // improvement due to the single `sqlite3_stmt_busy` check for
44
+ // database cursors.
41
45
try cursor. forEach { append ( $0) }
42
46
}
43
47
}
@@ -58,6 +62,9 @@ extension Dictionary {
58
62
throws where Value == [ C . Element ]
59
63
{
60
64
self . init ( )
65
+ // Prefer `forEach` over `next()` looping, as a slight performance
66
+ // improvement due to the single `sqlite3_stmt_busy` check for
67
+ // database cursors.
61
68
try cursor. forEach { value in
62
69
try self [ keyForValue ( value) , default: [ ] ] . append ( value)
63
70
}
@@ -84,6 +91,9 @@ extension Dictionary {
84
91
throws where Value == [ C . Element ]
85
92
{
86
93
self . init ( minimumCapacity: minimumCapacity)
94
+ // Prefer `forEach` over `next()` looping, as a slight performance
95
+ // improvement due to the single `sqlite3_stmt_busy` check for
96
+ // database cursors.
87
97
try cursor. forEach { value in
88
98
try self [ keyForValue ( value) , default: [ ] ] . append ( value)
89
99
}
@@ -106,6 +116,9 @@ extension Dictionary {
106
116
throws where C. Element == ( Key , Value )
107
117
{
108
118
self . init ( )
119
+ // Prefer `forEach` over `next()` looping, as a slight performance
120
+ // improvement due to the single `sqlite3_stmt_busy` check for
121
+ // database cursors.
109
122
try keysAndValues. forEach { key, value in
110
123
if updateValue ( value, forKey: key) != nil {
111
124
fatalError ( " Duplicate values for key: ' \( String ( describing: key) ) ' " )
@@ -135,6 +148,9 @@ extension Dictionary {
135
148
throws where C. Element == ( Key , Value )
136
149
{
137
150
self . init ( minimumCapacity: minimumCapacity)
151
+ // Prefer `forEach` over `next()` looping, as a slight performance
152
+ // improvement due to the single `sqlite3_stmt_busy` check for
153
+ // database cursors.
138
154
try keysAndValues. forEach { key, value in
139
155
if updateValue ( value, forKey: key) != nil {
140
156
fatalError ( " Duplicate values for key: ' \( String ( describing: key) ) ' " )
@@ -153,6 +169,9 @@ extension Set {
153
169
/// - parameter cursor: A cursor of values to gather into a set.
154
170
public init < C: Cursor > ( _ cursor: C ) throws where C. Element == Element {
155
171
self . init ( )
172
+ // Prefer `forEach` over `next()` looping, as a slight performance
173
+ // improvement due to the single `sqlite3_stmt_busy` check for
174
+ // database cursors.
156
175
try cursor. forEach { insert ( $0) }
157
176
}
158
177
@@ -168,6 +187,9 @@ extension Set {
168
187
/// storage buffer.
169
188
public init < C: Cursor > ( _ cursor: C , minimumCapacity: Int ) throws where C. Element == Element {
170
189
self . init ( minimumCapacity: minimumCapacity)
190
+ // Prefer `forEach` over `next()` looping, as a slight performance
191
+ // improvement due to the single `sqlite3_stmt_busy` check for
192
+ // database cursors.
171
193
try cursor. forEach { insert ( $0) }
172
194
}
173
195
}
0 commit comments