Skip to content

Commit 86d1054

Browse files
committed
Cleanup: Snapshot.init
1 parent fdae56b commit 86d1054

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Sources/DiffableTextKit/Models/Snapshot.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,12 @@ extension Snapshot {
8686
//=------------------------------------------------------------------------=
8787

8888
@inlinable public init(_ characters: String, as attribute: Attribute = .content) {
89-
self._characters = characters
90-
self._attributes = Array(repeating: attribute, count: characters.count)
91-
}
92-
93-
@inlinable public init<C>(_ characters: C, as attribute: Attribute = .content)
94-
where C: RandomAccessCollection, C.Element == Character {
95-
self._characters = String(characters)
96-
self._attributes = Array(repeating: attribute, count: characters.count)
89+
self.init(characters, as: { _ in attribute })
9790
}
9891

9992
@inlinable public init<S>(_ characters: S, as attribute: Attribute = .content)
100-
where S: Sequence, S.Element == Character { self.init()
101-
for character in characters {
102-
self._characters.append(character)
103-
self._attributes.append(attribute)
104-
}
93+
where S: Sequence, S.Element == Character {
94+
self.init(characters, as: { _ in attribute })
10595
}
10696

10797
//=------------------------------------------------------------------------=
@@ -116,6 +106,16 @@ extension Snapshot {
116106
self._attributes.append(attribute(character))
117107
}
118108
}
109+
110+
@inlinable public init<S>(_ characters: S, as attribute: (Character) -> Attribute)
111+
where S: Sequence, S.Element == Character {
112+
self.init()
113+
114+
for character in characters {
115+
self._characters.append(character)
116+
self._attributes.append(attribute(character))
117+
}
118+
}
119119
}
120120

121121
//=----------------------------------------------------------------------------=

0 commit comments

Comments
 (0)