Skip to content

[Parser] Cleanup UnicodeScalar handling #2516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 29, 2024

Mostly just removing redundant UnicodeScalar() callings.

Change associated type of EscapedCharacterLex.success(UInt32) and CharacterLex.validatedEscapeSequence(Character) to both Unicode.Scalar because there's no reason not to use it, and to avoid unnecessary conversions.

Comment on lines -74 to +79
var text = content.text
text.withUTF8 { buffer in
let rawText = content.rawText
if !rawText.contains("\\") {
// Fast path. No escape sequence.
output.append(String(syntaxText: rawText))
return
}
Copy link
Member Author

@rintaro rintaro Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fast path is an addition. It's probably just faster than always lexing the UTF8 sequence.

@rintaro
Copy link
Member Author

rintaro commented Feb 29, 2024

@swift-ci Please test

Make both EscapedCharacterLex and CharacterLex return 'Unicode.Scalar'
for escaped character result. It didn't have to be 'UTF32' or
'Character'. Avoid unnecessary conversions.
…Value()

If the segment doesn't have '\' in it. We don't need to go back to Lexer
to get the unescaped chanacters.
Unicode.Scalar conforms to 'ExpressibleByUnicodeScalarLiteral'. Literal
is enough.'
@rintaro rintaro force-pushed the parser-unicodescalar branch from 69eae7b to e07ae2b Compare February 29, 2024 23:52
@rintaro
Copy link
Member Author

rintaro commented Feb 29, 2024

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Mar 1, 2024

@swift-ci Please test

@rintaro rintaro merged commit cd9a97f into swiftlang:main Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants