Skip to content

Commit 578be41

Browse files
authored
Merge pull request #1132 from justinmeiners/quoted-performance
Improve string quote performance
2 parents 593a749 + b45781a commit 578be41

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/SQLite/Helpers.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ extension Optional: _OptionalType {
5454
let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
5555

5656
extension String {
57-
5857
func quote(_ mark: Character = "\"") -> String {
59-
let escaped = reduce("") { string, character in
60-
string + (character == mark ? "\(mark)\(mark)" : "\(character)")
58+
var quoted = ""
59+
quoted.append(mark)
60+
for character in self {
61+
quoted.append(character)
62+
if character == mark {
63+
quoted.append(character)
64+
}
6165
}
62-
return "\(mark)\(escaped)\(mark)"
66+
quoted.append(mark)
67+
return quoted
6368
}
6469

6570
func join(_ expressions: [Expressible]) -> Expressible {

0 commit comments

Comments
 (0)