From b45781a6659e186f85509a83b3678d4701221cc6 Mon Sep 17 00:00:00 2001 From: Justin Meiners Date: Mon, 9 May 2022 15:06:50 -0600 Subject: [PATCH] Improve string quote performance --- Sources/SQLite/Helpers.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/SQLite/Helpers.swift b/Sources/SQLite/Helpers.swift index d4c6828e..e3d37e11 100644 --- a/Sources/SQLite/Helpers.swift +++ b/Sources/SQLite/Helpers.swift @@ -54,12 +54,17 @@ extension Optional: _OptionalType { let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self) extension String { - func quote(_ mark: Character = "\"") -> String { - let escaped = reduce("") { string, character in - string + (character == mark ? "\(mark)\(mark)" : "\(character)") + var quoted = "" + quoted.append(mark) + for character in self { + quoted.append(character) + if character == mark { + quoted.append(character) + } } - return "\(mark)\(escaped)\(mark)" + quoted.append(mark) + return quoted } func join(_ expressions: [Expressible]) -> Expressible {