You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the recent improvements to Swift's String type (UTF8 storage, isAscii performance flag, etc), it seems about time to replace all uses of NSString and NSMutableString.
This could potentially become a huge refactoring, as NSString and NSRange are everywhere. Maybe we should introduce a custom type ASCIIString (backed by a String or gasp! maybe even a ContiguousArray<CChar>?) that provides Int- and NSRange-based indexing and slicing similar to NSString (but assuming ASCII-only strings). This way, most of the existing code wouldn't need to change.
Note: for any code dealing with Unicode text (e.g., input transformation code), expect subtle issues because of differences how NSString and String report the length of a string: NSString.length is the number of UTF-16 code units, while String.length returns the number of perceived characters.
Example (insertedText is an NSMutableString):
(lldb) po insertedText
À
(lldb) po insertedText.length
2
This shouldn't be a problem in most of the code, though, because it's ASCII except for the input stage.
Performance-related: be careful / verify if SourceModel's texSource is referenced only by SourceModel, to prevent triggering creating copies (CoW) when modifying the string.
ktraunmueller
changed the title
Replace NSString everywhere
Introduce custom ASCII string type for source handling
Jul 8, 2019
ktraunmueller
changed the title
Introduce custom ASCII string type for source handling
Introduce custom ASCII string type for all source manipulation
Jul 8, 2019
With the recent improvements to Swift's String type (UTF8 storage, isAscii performance flag, etc), it seems about time to replace all uses of NSString and NSMutableString.
This could potentially become a huge refactoring, as
NSString
andNSRange
are everywhere. Maybe we should introduce a custom typeASCIIString
(backed by aString
or gasp! maybe even aContiguousArray<CChar>
?) that providesInt
- andNSRange
-based indexing and slicing similar toNSString
(but assuming ASCII-only strings). This way, most of the existing code wouldn't need to change.Note: for any code dealing with Unicode text (e.g., input transformation code), expect subtle issues because of differences how
NSString
andString
report the length of a string:NSString.length
is the number of UTF-16 code units, whileString.length
returns the number of perceived characters.Example (
insertedText
is anNSMutableString
):This shouldn't be a problem in most of the code, though, because it's ASCII except for the input stage.
Performance-related: be careful / verify if
SourceModel
'stexSource
is referenced only bySourceModel
, to prevent triggering creating copies (CoW) when modifying the string.Prerequisites: #468
The text was updated successfully, but these errors were encountered: