Status as class (performance improvement) (#925)

* Status as class (performance improvement)

* Also make account class

---------

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
Alex Grebenyuk 2023-02-18 01:15:57 -05:00 committed by GitHub
parent 88fdeec100
commit dcf03b0f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 3 deletions

View File

@ -1,6 +1,10 @@
import Foundation
public struct Account: Codable, Identifiable, Equatable, Hashable {
public final class Account: Codable, Identifiable, Equatable, Hashable {
public static func == (lhs: Account, rhs: Account) -> Bool {
lhs.id == rhs.id
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
@ -51,6 +55,29 @@ public struct Account: Codable, Identifiable, Equatable, Hashable {
return header.lastPathComponent != "missing.png"
}
public init(id: String, username: String, displayName: String, avatar: URL, header: URL, acct: String, note: HTMLString, createdAt: ServerDate, followersCount: Int, followingCount: Int, statusesCount: Int, lastStatusAt: String? = nil, fields: [Account.Field], locked: Bool, emojis: [Emoji], url: URL? = nil, source: Account.Source? = nil, bot: Bool, discoverable: Bool? = nil) {
self.id = id
self.username = username
self.displayName = displayName
self.avatar = avatar
self.header = header
self.acct = acct
self.note = note
self.createdAt = createdAt
self.followersCount = followersCount
self.followingCount = followingCount
self.statusesCount = statusesCount
self.lastStatusAt = lastStatusAt
self.fields = fields
self.locked = locked
self.emojis = emojis
self.url = url
self.source = source
self.bot = bot
self.discoverable = discoverable
}
public static func placeholder() -> Account {
.init(id: UUID().uuidString,
username: "Username",

View File

@ -68,7 +68,7 @@ protocol StatusUI {
var userMentioned: Bool? { get set }
}
public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, StatusUI {
public final class Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, StatusUI {
public var userMentioned: Bool?
public static func == (lhs: Status, rhs: Status) -> Bool {
@ -107,6 +107,37 @@ public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, Sta
public let sensitive: Bool
public let language: String?
public init(userMentioned: Bool? = nil, id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, reblog: ReblogStatus?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application?, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {
self.userMentioned = userMentioned
self.id = id
self.content = content
self.account = account
self.createdAt = createdAt
self.editedAt = editedAt
self.reblog = reblog
self.mediaAttachments = mediaAttachments
self.mentions = mentions
self.repliesCount = repliesCount
self.reblogsCount = reblogsCount
self.favouritesCount = favouritesCount
self.card = card
self.favourited = favourited
self.reblogged = reblogged
self.pinned = pinned
self.bookmarked = bookmarked
self.emojis = emojis
self.url = url
self.application = application
self.inReplyToId = inReplyToId
self.inReplyToAccountId = inReplyToAccountId
self.visibility = visibility
self.poll = poll
self.spoilerText = spoilerText
self.filtered = filtered
self.sensitive = sensitive
self.language = language
}
public static func placeholder(forSettings: Bool = false, language: String? = nil) -> Status {
.init(id: UUID().uuidString,
content: .init(stringValue: "Lorem ipsum [#dolor](#) sit amet\nconsectetur [@adipiscing](#) elit\nAsed do eiusmod tempor incididunt ut labore.", parseMarkdown: forSettings),
@ -176,7 +207,7 @@ public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, Sta
}
}
public struct ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Hashable {
public final class ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Hashable {
public static func == (lhs: ReblogStatus, rhs: ReblogStatus) -> Bool {
lhs.id == rhs.id
}
@ -211,4 +242,33 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Hashabl
public let filtered: [Filtered]?
public let sensitive: Bool
public let language: String?
public init(id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application? = nil, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {
self.id = id
self.content = content
self.account = account
self.createdAt = createdAt
self.editedAt = editedAt
self.mediaAttachments = mediaAttachments
self.mentions = mentions
self.repliesCount = repliesCount
self.reblogsCount = reblogsCount
self.favouritesCount = favouritesCount
self.card = card
self.favourited = favourited
self.reblogged = reblogged
self.pinned = pinned
self.bookmarked = bookmarked
self.emojis = emojis
self.url = url
self.application = application
self.inReplyToId = inReplyToId
self.inReplyToAccountId = inReplyToAccountId
self.visibility = visibility
self.poll = poll
self.spoilerText = spoilerText
self.filtered = filtered
self.sensitive = sensitive
self.language = language
}
}