Skip to content

Commit dd67ff5

Browse files
authored
Merge pull request #81 from vzsg/dictionary-reuse
Reuse the parsed dictionary during a query to reduce allocations
2 parents 80a5210 + 5a6b9b4 commit dd67ff5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/MySQL/Connection.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ public final class Connection {
132132

133133
var results: [[String: Node]] = []
134134

135+
// This single dictionary is reused for all rows in the result set
136+
// to avoid the runtime overhead of (de)allocating one per row.
137+
var parsed: [String: Node] = [:]
138+
135139
// Iterate over all of the rows that are returned.
136140
// `mysql_stmt_fetch` will continue to return `0`
137141
// as long as there are rows to be fetched.
138142
while mysql_stmt_fetch(statement) == 0 {
139-
var parsed: [String: Node] = [:]
140-
141143
// For each row, loop over all of the fields expected.
142144
for (i, field) in fields.fields.enumerated() {
143145

0 commit comments

Comments
 (0)