-
Notifications
You must be signed in to change notification settings - Fork 149
Fixes large text memory issue. #795
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
Fixes large text memory issue. #795
Conversation
| return textStore.attributes(at: location, effectiveRange: range) | ||
| } | ||
|
|
||
| private func replaceTextStoreString(_ range: NSRange, with string: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering String.replaceSubrange() is of complexity O(m) for most scenarios (where m is the sum of the length of the cached string and the modification), this method should be replaced by:
textStoreString = textStore.string
| detectAttachmentRemoved(in: range) | ||
| textStore.replaceCharacters(in: range, with: str) | ||
|
|
||
| replaceTextStoreString(range, with: str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move the update logic inside of override func edited() (inside the next call in this method), and only trigger it for .editedCharacters.
That way we don't need to call both at several point in the app.
|
@azone - Very nice find and very nice approach. Added a few comments on further improvements. |
diegoreymendez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aproving, since we need these changes. I'll address any changes separately.
|
Merging since Travis is stuck. |
Fixes #791
To test: