From 8b06257d17110d7c127f0b2dc0698f7451633390 Mon Sep 17 00:00:00 2001 From: Pedro Carrasco Date: Wed, 3 Apr 2019 13:07:03 +0100 Subject: [PATCH] Improved Collection Safe Subscript Performance --- Sucrose.podspec | 2 +- Sucrose/Extensions/Collection+SafeIndex.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sucrose.podspec b/Sucrose.podspec index 4bd3515..aff9080 100644 --- a/Sucrose.podspec +++ b/Sucrose.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.swift_version = "5.0" s.name = "Sucrose" - s.version = "3.3.0" + s.version = "3.3.1" s.summary = "🍬 Everyday sugar" s.description = "Collection of handy methods & objects" diff --git a/Sucrose/Extensions/Collection+SafeIndex.swift b/Sucrose/Extensions/Collection+SafeIndex.swift index 6876824..a1cd97c 100644 --- a/Sucrose/Extensions/Collection+SafeIndex.swift +++ b/Sucrose/Extensions/Collection+SafeIndex.swift @@ -11,6 +11,6 @@ import Foundation public extension Collection { subscript(safe index: Index) -> Element? { - return indices.contains(index) ? self[index] : nil + return index < endIndex && index >= startIndex ? self[index] : nil } }