Skip to content

Commit 57d3b8f

Browse files
Simplify string isAllWhitespace implementation (#235)
This patch is really very simple one, but I believe can be both a simplification on implementation and a perf improvement in the sense that as it is if we take for example as reference the implementation of [`trimmingCharacters`](https://github.com/apple/swift-corelibs-foundation/blob/34887cb2615e903cbe7ad428a538ee27be5a7d39/Sources/Foundation/NSString.swift#L1162) we note that it will do a lot extra work as allocating buffers or a whole new string maybe, when this only need a simple check that can exit early and also avoid those extra allocations.
1 parent 88a4aa9 commit 57d3b8f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Sources/XMLCoder/Auxiliaries/String+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ extension StringProtocol {
4747

4848
extension String {
4949
func isAllWhitespace() -> Bool {
50-
return self.trimmingCharacters(in: .whitespacesAndNewlines) == ""
50+
return unicodeScalars.allSatisfy(CharacterSet.whitespacesAndNewlines.contains)
5151
}
5252
}

0 commit comments

Comments
 (0)