From 7f48e66fdc2e7e5afbb3c8be0f23890d250eba95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 26 Feb 2021 18:50:47 +0100 Subject: [PATCH] Reduce inlined code --- GRDB/Core/RowDecodingError.swift | 17 ++++++++++++++++- GRDB/Core/StatementColumnConvertible.swift | 11 ++++++----- GRDB/Core/Support/Foundation/Data.swift | 5 +++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/GRDB/Core/RowDecodingError.swift b/GRDB/Core/RowDecodingError.swift index ded2d9427..6392886ec 100644 --- a/GRDB/Core/RowDecodingError.swift +++ b/GRDB/Core/RowDecodingError.swift @@ -58,7 +58,6 @@ enum RowDecodingError: Error { /// Convenience method that builds the /// `could not decode from database value ` error message. - @usableFromInline static func valueMismatch( _ type: Any.Type, context: RowDecodingContext, @@ -72,6 +71,22 @@ enum RowDecodingError: Error { """)) } + /// Convenience method that builds the + /// `could not decode from database value ` error message. + @usableFromInline + static func valueMismatch( + _ type: Any.Type, + sqliteStatement: SQLiteStatement, + index: Int32, + context: RowDecodingContext) + -> Self + { + valueMismatch( + type, + context: context, + databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index)) + } + /// Convenience method that builds the /// `could not decode from database value ` error message. @usableFromInline diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index e5a75f490..50a2d6835 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -57,8 +57,9 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { else { throw RowDecodingError.valueMismatch( Self.self, - context: context(), - databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index)) + sqliteStatement: sqliteStatement, + index: index, + context: context()) } return value } @@ -90,11 +91,11 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return nil } guard let value = self.init(sqliteStatement: sqliteStatement, index: index) else { - #warning("TODO: don't put the DatabaseValue in the inlined code") throw RowDecodingError.valueMismatch( Self.self, - context: context(), - databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index)) + sqliteStatement: sqliteStatement, + index: index, + context: context()) } return value } diff --git a/GRDB/Core/Support/Foundation/Data.swift b/GRDB/Core/Support/Foundation/Data.swift index 4be05988c..42a853466 100644 --- a/GRDB/Core/Support/Foundation/Data.swift +++ b/GRDB/Core/Support/Foundation/Data.swift @@ -46,8 +46,9 @@ extension Data { guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else { throw RowDecodingError.valueMismatch( Data.self, - context: context(), - databaseValue: DatabaseValue(sqliteStatement: sqliteStatement, index: index)) + sqliteStatement: sqliteStatement, + index: index, + context: context()) } guard let bytes = sqlite3_column_blob(sqliteStatement, Int32(index)) else { return Data()