From 41403c84f9f3a356184b94eb5cca8081a3aeb93f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 29 Dec 2020 11:54:02 -0500 Subject: [PATCH] Don't allocate a new Set every time timeAgo is computed --- Tusker/Extensions/Date+TimeAgo.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tusker/Extensions/Date+TimeAgo.swift b/Tusker/Extensions/Date+TimeAgo.swift index bca179dd..bce334e2 100644 --- a/Tusker/Extensions/Date+TimeAgo.swift +++ b/Tusker/Extensions/Date+TimeAgo.swift @@ -10,11 +10,11 @@ import Foundation extension Date { + private static let unitFlags = Set([.second, .minute, .hour, .day, .weekOfYear, .month, .year]) + func timeAgo() -> (Int, Calendar.Component) { let calendar = NSCalendar.current - let unitFlags = Set([.second, .minute, .hour, .day, .weekOfYear, .month, .year]) - - let components = calendar.dateComponents(unitFlags, from: self, to: Date()) + let components = calendar.dateComponents(Date.unitFlags, from: self, to: Date()) if components.year! >= 1 { return (components.year!, .year)