-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor: Use more exact allocations in
insert_newline
This is partially a style commit: * Pull more bindings out the `change_by_selection` closure like the line-ending string and the comment tokens used for continuation. * Prefer `Editor::config` to `Document`'s config. The rest is changes to places where `insert_newline` may allocate. The first is to move `new_text` out of the `change_by_selection` closure, reusing it between iterations. This is not necessarily always an improvement as we need to clone the text for the return type of the closure. `SmartString`'s `From<String>` implementation reuses the allocation when the string is too long to inline and drops it if it is short enough to inline though which can be wasteful. `From<&String>` clones the string's allocation only when it is too long to be inlined, so we save on allocations for any `new_text` short enough to be inlined. The rest is changes to `new_text.reserve_exact`. Previously calls to this function in this block mixed up character and byte indexing by treating the length of the line-ending as 1. `reserve_exact` takes a number of bytes to reserve and that may be 2 when `line_ending` is a CRLF. A call to `reserve_exact` is also added to the branch used when continuing line comments.
- Loading branch information
1 parent
4bd17e5
commit 3318953
Showing
1 changed file
with
25 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters