Removing unnecessary allocations and more
This pull request does:
- removes a lot of unnecessary memory allocations. For example, previously, multiple allocations of vectors were performed in a loop to store a single character (function
lapce_core::syntax::Syntax::find_matching_pair); - removes many indirect function calls. For example calling ~~
to_string()on a&' static str~~, using"".to_string()instead ofString::new().
In addition, a complete rewrite of the Snippet::extract_text function was performed while preserving the logic of its work. This was done, firstly, to remove the constant copying of immutable vectors in a loop. Secondly, to exclude a possible crash of the program, since accessing an element by index for a string is not a good idea.
- [ ] Added an entry to
CHANGELOG.mdif this change could be valuable to users
~~what's wrong with String::new()?~~ misread that
Codecov Report
Merging #1796 (0551acb) into master (7a2f342) will increase coverage by
0.76%. The diff coverage is72.02%.
@@ Coverage Diff @@
## master #1796 +/- ##
=========================================
+ Coverage 6.39% 7.16% +0.76%
=========================================
Files 128 129 +1
Lines 55350 55861 +511
=========================================
+ Hits 3542 4000 +458
- Misses 51808 51861 +53
| Impacted Files | Coverage Δ | |
|---|---|---|
| lapce-core/src/cursor.rs | 5.11% <0.00%> (-0.02%) |
:arrow_down: |
| lapce-core/src/lib.rs | 100.00% <ø> (ø) |
|
| lapce-core/src/syntax/mod.rs | 7.30% <0.00%> (+0.02%) |
:arrow_up: |
| lapce-data/src/alert.rs | 0.00% <0.00%> (ø) |
|
| lapce-data/src/config.rs | 0.00% <0.00%> (ø) |
|
| lapce-data/src/data.rs | 0.00% <0.00%> (ø) |
|
| lapce-data/src/db.rs | 0.00% <0.00%> (ø) |
|
| lapce-data/src/document.rs | 0.00% <0.00%> (ø) |
|
| lapce-data/src/editor.rs | 0.00% <0.00%> (ø) |
|
| lapce-data/src/keypress/mod.rs | 16.38% <0.00%> (ø) |
|
| ... and 38 more |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
@panekj Made requested fixes and improved some of my solutions. I think this pull request is ready for another review.
Where is the CharBuffer from (and why)?
Where is the
CharBufferfrom (and why)?
I wrote it myself as a helper structure to store a one-character &str on the stack instead of on the heap. I thought it would be a useful structure both now and later.
And well, since this is a structure for storing a "string slice", then it must be done correctly so that it can be compared with other string structures, converted from one structure to another and vice versa, it must have documentation and tests.
The name may not be very good, but I couldn't think of a better one.
Is there anything left to do?
Is there anything left to do?
Yes, I need to clean up the PR by removing things that have already merged. Can't do it right now as I'm busy developing generic traits for containers/collections.