Skip to content

Commit 1dc4c16

Browse files
committed
Squashed commit of the following:
commit 4cd9756 Author: Ruslan Alikhamov <[email protected]> Date: Mon Oct 23 22:17:28 2023 +0400 applied swift-format commit dc59e96 Author: Ruslan Alikhamov <[email protected]> Date: Mon Oct 23 22:02:35 2023 +0400 removed redundant variable commit ff95302 Author: Ruslan Alikhamov <[email protected]> Date: Mon Oct 23 22:00:23 2023 +0400 refactored optimization in isValidIdentifierContinuationCodePoint commit 5b94ec9 Author: Ruslan Alikhamov <[email protected]> Date: Mon Oct 23 21:51:48 2023 +0400 fixed a typo; renamed variables commit 7e1f23d Author: Ruslan Alikhamov <[email protected]> Date: Mon Oct 23 21:38:08 2023 +0400 renamed variables in slice(of:) commit 3b9c1f8 Author: Ruslan Alikhamov <[email protected]> Date: Sat Oct 21 19:45:34 2023 +0400 removed redundant newline commit 83ad08c Author: Ruslan Alikhamov <[email protected]> Date: Sat Oct 21 19:02:13 2023 +0400 optimized isSlice(of other: SyntaxText) -> Bool commit f5d0a3a Author: Ruslan Alikhamov <[email protected]> Date: Sat Oct 21 19:02:03 2023 +0400 optimized isValidIdentifierContinuationCodePoint
1 parent f8be751 commit 1dc4c16

File tree

2 files changed

+55
-47
lines changed

2 files changed

+55
-47
lines changed

Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,58 @@ extension Unicode.Scalar {
1919
// N1518: Recommendations for extended identifier characters for C and C++
2020
// Proposed Annex X.1: Ranges of characters allowed
2121
let c = self.value
22-
return c == 0x00A8 || c == 0x00AA || c == 0x00AD || c == 0x00AF
23-
|| (c >= 0x00B2 && c <= 0x00B5) || (c >= 0x00B7 && c <= 0x00BA)
24-
|| (c >= 0x00BC && c <= 0x00BE) || (c >= 0x00C0 && c <= 0x00D6)
25-
|| (c >= 0x00D8 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FF)
26-
27-
|| (c >= 0x0100 && c <= 0x167F)
28-
|| (c >= 0x1681 && c <= 0x180D)
29-
|| (c >= 0x180F && c <= 0x1FFF)
30-
31-
|| (c >= 0x200B && c <= 0x200D)
32-
|| (c >= 0x202A && c <= 0x202E)
33-
|| (c >= 0x203F && c <= 0x2040)
34-
|| c == 0x2054
35-
|| (c >= 0x2060 && c <= 0x206F)
36-
37-
|| (c >= 0x2070 && c <= 0x218F)
38-
|| (c >= 0x2460 && c <= 0x24FF)
39-
|| (c >= 0x2776 && c <= 0x2793)
40-
|| (c >= 0x2C00 && c <= 0x2DFF)
41-
|| (c >= 0x2E80 && c <= 0x2FFF)
42-
43-
|| (c >= 0x3004 && c <= 0x3007)
44-
|| (c >= 0x3021 && c <= 0x302F)
45-
|| (c >= 0x3031 && c <= 0x303F)
46-
47-
|| (c >= 0x3040 && c <= 0xD7FF)
48-
49-
|| (c >= 0xF900 && c <= 0xFD3D)
50-
|| (c >= 0xFD40 && c <= 0xFDCF)
51-
|| (c >= 0xFDF0 && c <= 0xFE44)
52-
|| (c >= 0xFE47 && c <= 0xFFF8)
53-
54-
|| (c >= 0x10000 && c <= 0x1FFFD)
55-
|| (c >= 0x20000 && c <= 0x2FFFD)
56-
|| (c >= 0x30000 && c <= 0x3FFFD)
57-
|| (c >= 0x40000 && c <= 0x4FFFD)
58-
|| (c >= 0x50000 && c <= 0x5FFFD)
59-
|| (c >= 0x60000 && c <= 0x6FFFD)
60-
|| (c >= 0x70000 && c <= 0x7FFFD)
61-
|| (c >= 0x80000 && c <= 0x8FFFD)
62-
|| (c >= 0x90000 && c <= 0x9FFFD)
63-
|| (c >= 0xA0000 && c <= 0xAFFFD)
64-
|| (c >= 0xB0000 && c <= 0xBFFFD)
65-
|| (c >= 0xC0000 && c <= 0xCFFFD)
66-
|| (c >= 0xD0000 && c <= 0xDFFFD)
67-
|| (c >= 0xE0000 && c <= 0xEFFFD)
22+
return (c == 0x00A8) as Bool
23+
|| (c == 0x00AA) as Bool
24+
|| (c == 0x00AD) as Bool
25+
|| (c == 0x00AF) as Bool
26+
|| (c >= 0x00B2 && c <= 0x00B5) as Bool
27+
|| (c >= 0x00B7 && c <= 0x00BA) as Bool
28+
|| (c >= 0x00BC && c <= 0x00BE) as Bool
29+
|| (c >= 0x00C0 && c <= 0x00D6) as Bool
30+
|| (c >= 0x00D8 && c <= 0x00F6) as Bool
31+
|| (c >= 0x00F8 && c <= 0x00FF) as Bool
32+
33+
|| (c >= 0x0100 && c <= 0x167F) as Bool
34+
|| (c >= 0x1681 && c <= 0x180D) as Bool
35+
|| (c >= 0x180F && c <= 0x1FFF) as Bool
36+
37+
|| (c >= 0x200B && c <= 0x200D) as Bool
38+
|| (c >= 0x202A && c <= 0x202E) as Bool
39+
|| (c >= 0x203F && c <= 0x2040) as Bool
40+
|| (c == 0x2054) as Bool
41+
|| (c >= 0x2060 && c <= 0x206F) as Bool
42+
43+
|| (c >= 0x2070 && c <= 0x218F) as Bool
44+
|| (c >= 0x2460 && c <= 0x24FF) as Bool
45+
|| (c >= 0x2776 && c <= 0x2793) as Bool
46+
|| (c >= 0x2C00 && c <= 0x2DFF) as Bool
47+
|| (c >= 0x2E80 && c <= 0x2FFF) as Bool
48+
49+
|| (c >= 0x3004 && c <= 0x3007) as Bool
50+
|| (c >= 0x3021 && c <= 0x302F) as Bool
51+
|| (c >= 0x3031 && c <= 0x303F) as Bool
52+
53+
|| (c >= 0x3040 && c <= 0xD7FF) as Bool
54+
55+
|| (c >= 0xF900 && c <= 0xFD3D) as Bool
56+
|| (c >= 0xFD40 && c <= 0xFDCF) as Bool
57+
|| (c >= 0xFDF0 && c <= 0xFE44) as Bool
58+
|| (c >= 0xFE47 && c <= 0xFFF8) as Bool
59+
60+
|| (c >= 0x10000 && c <= 0x1FFFD) as Bool
61+
|| (c >= 0x20000 && c <= 0x2FFFD) as Bool
62+
|| (c >= 0x30000 && c <= 0x3FFFD) as Bool
63+
|| (c >= 0x40000 && c <= 0x4FFFD) as Bool
64+
|| (c >= 0x50000 && c <= 0x5FFFD) as Bool
65+
|| (c >= 0x60000 && c <= 0x6FFFD) as Bool
66+
|| (c >= 0x70000 && c <= 0x7FFFD) as Bool
67+
|| (c >= 0x80000 && c <= 0x8FFFD) as Bool
68+
|| (c >= 0x90000 && c <= 0x9FFFD) as Bool
69+
|| (c >= 0xA0000 && c <= 0xAFFFD) as Bool
70+
|| (c >= 0xB0000 && c <= 0xBFFFD) as Bool
71+
|| (c >= 0xC0000 && c <= 0xCFFFD) as Bool
72+
|| (c >= 0xD0000 && c <= 0xDFFFD) as Bool
73+
|| (c >= 0xE0000 && c <= 0xEFFFD) as Bool
6874
}
6975

7076
var isValidIdentifierStartCodePoint: Bool {

Sources/SwiftSyntax/SyntaxText.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public struct SyntaxText {
100100
guard !self.isEmpty && !other.isEmpty else {
101101
return self.isEmpty && other.isEmpty
102102
}
103-
return (other.baseAddress! <= self.baseAddress! && self.baseAddress! + count <= other.baseAddress! + other.count)
103+
let selfEndBound = UnsafePointer<UInt8>(self.baseAddress! + count)
104+
let otherEndBound = UnsafePointer<UInt8>(other.baseAddress! + other.count)
105+
return (other.baseAddress! <= self.baseAddress!) && (selfEndBound <= otherEndBound)
104106
}
105107

106108
/// Returns `true` if `other` is a substring of this ``SyntaxText``.

0 commit comments

Comments
 (0)