From 1dc4c162ebeb8280abfcf56e190d49284942293c Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Mon, 23 Oct 2023 22:35:34 +0400 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 4cd97568099ff03aa9edce1cdadf9030336d2931 Author: Ruslan Alikhamov Date: Mon Oct 23 22:17:28 2023 +0400 applied swift-format commit dc59e96cff056f46051777feee220b75bd0a3878 Author: Ruslan Alikhamov Date: Mon Oct 23 22:02:35 2023 +0400 removed redundant variable commit ff953021cb8ee75127b979e33209abb5cd9ea7ba Author: Ruslan Alikhamov Date: Mon Oct 23 22:00:23 2023 +0400 refactored optimization in isValidIdentifierContinuationCodePoint commit 5b94ec9ba640d6e033b6f02976cc86fb7cbee273 Author: Ruslan Alikhamov Date: Mon Oct 23 21:51:48 2023 +0400 fixed a typo; renamed variables commit 7e1f23dca379df7b0421de78910aa5fe42b3da9c Author: Ruslan Alikhamov Date: Mon Oct 23 21:38:08 2023 +0400 renamed variables in slice(of:) commit 3b9c1f88829a83748659744af8002886a24700af Author: Ruslan Alikhamov Date: Sat Oct 21 19:45:34 2023 +0400 removed redundant newline commit 83ad08cb0602bf540ad356c922d1000af59eaa73 Author: Ruslan Alikhamov Date: Sat Oct 21 19:02:13 2023 +0400 optimized isSlice(of other: SyntaxText) -> Bool commit f5d0a3a1ab5b426cf5927f726a2faf33dda4aa3d Author: Ruslan Alikhamov Date: Sat Oct 21 19:02:03 2023 +0400 optimized isValidIdentifierContinuationCodePoint --- .../Lexer/UnicodeScalarExtensions.swift | 98 ++++++++++--------- Sources/SwiftSyntax/SyntaxText.swift | 4 +- 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift b/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift index 52774807220..03e86252c75 100644 --- a/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift +++ b/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift @@ -19,52 +19,58 @@ extension Unicode.Scalar { // N1518: Recommendations for extended identifier characters for C and C++ // Proposed Annex X.1: Ranges of characters allowed let c = self.value - return c == 0x00A8 || c == 0x00AA || c == 0x00AD || c == 0x00AF - || (c >= 0x00B2 && c <= 0x00B5) || (c >= 0x00B7 && c <= 0x00BA) - || (c >= 0x00BC && c <= 0x00BE) || (c >= 0x00C0 && c <= 0x00D6) - || (c >= 0x00D8 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FF) - - || (c >= 0x0100 && c <= 0x167F) - || (c >= 0x1681 && c <= 0x180D) - || (c >= 0x180F && c <= 0x1FFF) - - || (c >= 0x200B && c <= 0x200D) - || (c >= 0x202A && c <= 0x202E) - || (c >= 0x203F && c <= 0x2040) - || c == 0x2054 - || (c >= 0x2060 && c <= 0x206F) - - || (c >= 0x2070 && c <= 0x218F) - || (c >= 0x2460 && c <= 0x24FF) - || (c >= 0x2776 && c <= 0x2793) - || (c >= 0x2C00 && c <= 0x2DFF) - || (c >= 0x2E80 && c <= 0x2FFF) - - || (c >= 0x3004 && c <= 0x3007) - || (c >= 0x3021 && c <= 0x302F) - || (c >= 0x3031 && c <= 0x303F) - - || (c >= 0x3040 && c <= 0xD7FF) - - || (c >= 0xF900 && c <= 0xFD3D) - || (c >= 0xFD40 && c <= 0xFDCF) - || (c >= 0xFDF0 && c <= 0xFE44) - || (c >= 0xFE47 && c <= 0xFFF8) - - || (c >= 0x10000 && c <= 0x1FFFD) - || (c >= 0x20000 && c <= 0x2FFFD) - || (c >= 0x30000 && c <= 0x3FFFD) - || (c >= 0x40000 && c <= 0x4FFFD) - || (c >= 0x50000 && c <= 0x5FFFD) - || (c >= 0x60000 && c <= 0x6FFFD) - || (c >= 0x70000 && c <= 0x7FFFD) - || (c >= 0x80000 && c <= 0x8FFFD) - || (c >= 0x90000 && c <= 0x9FFFD) - || (c >= 0xA0000 && c <= 0xAFFFD) - || (c >= 0xB0000 && c <= 0xBFFFD) - || (c >= 0xC0000 && c <= 0xCFFFD) - || (c >= 0xD0000 && c <= 0xDFFFD) - || (c >= 0xE0000 && c <= 0xEFFFD) + return (c == 0x00A8) as Bool + || (c == 0x00AA) as Bool + || (c == 0x00AD) as Bool + || (c == 0x00AF) as Bool + || (c >= 0x00B2 && c <= 0x00B5) as Bool + || (c >= 0x00B7 && c <= 0x00BA) as Bool + || (c >= 0x00BC && c <= 0x00BE) as Bool + || (c >= 0x00C0 && c <= 0x00D6) as Bool + || (c >= 0x00D8 && c <= 0x00F6) as Bool + || (c >= 0x00F8 && c <= 0x00FF) as Bool + + || (c >= 0x0100 && c <= 0x167F) as Bool + || (c >= 0x1681 && c <= 0x180D) as Bool + || (c >= 0x180F && c <= 0x1FFF) as Bool + + || (c >= 0x200B && c <= 0x200D) as Bool + || (c >= 0x202A && c <= 0x202E) as Bool + || (c >= 0x203F && c <= 0x2040) as Bool + || (c == 0x2054) as Bool + || (c >= 0x2060 && c <= 0x206F) as Bool + + || (c >= 0x2070 && c <= 0x218F) as Bool + || (c >= 0x2460 && c <= 0x24FF) as Bool + || (c >= 0x2776 && c <= 0x2793) as Bool + || (c >= 0x2C00 && c <= 0x2DFF) as Bool + || (c >= 0x2E80 && c <= 0x2FFF) as Bool + + || (c >= 0x3004 && c <= 0x3007) as Bool + || (c >= 0x3021 && c <= 0x302F) as Bool + || (c >= 0x3031 && c <= 0x303F) as Bool + + || (c >= 0x3040 && c <= 0xD7FF) as Bool + + || (c >= 0xF900 && c <= 0xFD3D) as Bool + || (c >= 0xFD40 && c <= 0xFDCF) as Bool + || (c >= 0xFDF0 && c <= 0xFE44) as Bool + || (c >= 0xFE47 && c <= 0xFFF8) as Bool + + || (c >= 0x10000 && c <= 0x1FFFD) as Bool + || (c >= 0x20000 && c <= 0x2FFFD) as Bool + || (c >= 0x30000 && c <= 0x3FFFD) as Bool + || (c >= 0x40000 && c <= 0x4FFFD) as Bool + || (c >= 0x50000 && c <= 0x5FFFD) as Bool + || (c >= 0x60000 && c <= 0x6FFFD) as Bool + || (c >= 0x70000 && c <= 0x7FFFD) as Bool + || (c >= 0x80000 && c <= 0x8FFFD) as Bool + || (c >= 0x90000 && c <= 0x9FFFD) as Bool + || (c >= 0xA0000 && c <= 0xAFFFD) as Bool + || (c >= 0xB0000 && c <= 0xBFFFD) as Bool + || (c >= 0xC0000 && c <= 0xCFFFD) as Bool + || (c >= 0xD0000 && c <= 0xDFFFD) as Bool + || (c >= 0xE0000 && c <= 0xEFFFD) as Bool } var isValidIdentifierStartCodePoint: Bool { diff --git a/Sources/SwiftSyntax/SyntaxText.swift b/Sources/SwiftSyntax/SyntaxText.swift index 310bcb22836..c5068a76aa4 100644 --- a/Sources/SwiftSyntax/SyntaxText.swift +++ b/Sources/SwiftSyntax/SyntaxText.swift @@ -100,7 +100,9 @@ public struct SyntaxText { guard !self.isEmpty && !other.isEmpty else { return self.isEmpty && other.isEmpty } - return (other.baseAddress! <= self.baseAddress! && self.baseAddress! + count <= other.baseAddress! + other.count) + let selfEndBound = UnsafePointer(self.baseAddress! + count) + let otherEndBound = UnsafePointer(other.baseAddress! + other.count) + return (other.baseAddress! <= self.baseAddress!) && (selfEndBound <= otherEndBound) } /// Returns `true` if `other` is a substring of this ``SyntaxText``.