From c0c8eec75d9b175122a6bec5a980180ebdce663b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 28 Aug 2021 13:39:22 +0200 Subject: [PATCH] Replace _checkedIndex with _checkIndex That's what the stdlib Array does --- GRDB/Core/Row.swift | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index b223bb713..6d5adc49e 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -168,9 +168,8 @@ extension Row { /// Fatal errors if index is out of bounds @inline(__always) @usableFromInline - /* private */ func _checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int { + /* private */ func _checkIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) { GRDBPrecondition(index >= 0 && index < count, "row index out of range", file: file, line: line) - return index } /// Returns true if and only if one column contains a non-null value, or if @@ -205,7 +204,8 @@ extension Row { /// in performance-critical code because it can avoid decoding database /// values. public func hasNull(atIndex index: Int) -> Bool { - impl.hasNull(atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return impl.hasNull(atUncheckedIndex: index) } /// Returns Int64, Double, String, Data or nil, depending on the value @@ -214,7 +214,8 @@ extension Row { /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. public subscript(_ index: Int) -> DatabaseValueConvertible? { - impl.databaseValue(atUncheckedIndex: _checkedIndex(index)).storage.value + _checkIndex(index) + return impl.databaseValue(atUncheckedIndex: index).storage.value } /// Returns the value at given index, converted to the requested type. @@ -715,7 +716,8 @@ extension Row { atIndex index: Int) throws -> Value? { - try Value.decodeIfPresent(fromRow: self, atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return try Value.decodeIfPresent(fromRow: self, atUncheckedIndex: index) } /// Returns the value at given index, converted to the requested type. @@ -731,7 +733,8 @@ extension Row { atIndex index: Int) throws -> Value { - try Value.decode(fromRow: self, atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return try Value.decode(fromRow: self, atUncheckedIndex: index) } /// Returns the value at given column, converted to the requested type. @@ -797,7 +800,8 @@ extension Row { atIndex index: Int) throws -> Value? { - try Value.fastDecodeIfPresent(fromRow: self, atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return try Value.fastDecodeIfPresent(fromRow: self, atUncheckedIndex: index) } /// Returns the value at given index, converted to the requested type. @@ -818,7 +822,8 @@ extension Row { atIndex index: Int) throws -> Value { - try Value.fastDecode(fromRow: self, atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return try Value.fastDecode(fromRow: self, atUncheckedIndex: index) } /// Returns the value at given column, converted to the requested type. @@ -905,7 +910,8 @@ extension Row { /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. func decodeDataNoCopyIfPresent(atIndex index: Int) throws -> Data? { - try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: index) } /// Returns the Data at given index. @@ -919,7 +925,8 @@ extension Row { /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. func decodeDataNoCopy(atIndex index: Int) throws -> Data { - try impl.fastDecodeDataNoCopy(atUncheckedIndex: _checkedIndex(index)) + _checkIndex(index) + return try impl.fastDecodeDataNoCopy(atUncheckedIndex: index) } /// Returns the optional Data at given column. @@ -1663,7 +1670,8 @@ extension Row { /// Accesses the (ColumnName, DatabaseValue) pair at given index. public subscript(position: RowIndex) -> (String, DatabaseValue) { - let index = _checkedIndex(position.index) + let index = position.index + _checkIndex(index) return ( impl.columnName(atUncheckedIndex: index), impl.databaseValue(atUncheckedIndex: index))