lapce icon indicating copy to clipboard operation
lapce copied to clipboard

Removing unnecessary allocations and more

Open JustForFun88 opened this issue 3 years ago • 5 comments

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 of String::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.md if this change could be valuable to users

JustForFun88 avatar Dec 10 '22 11:12 JustForFun88

~~what's wrong with String::new()?~~ misread that

panekj avatar Dec 10 '22 12:12 panekj

Codecov Report

Merging #1796 (0551acb) into master (7a2f342) will increase coverage by 0.76%. The diff coverage is 72.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

codecov-commenter avatar Dec 11 '22 15:12 codecov-commenter

@panekj Made requested fixes and improved some of my solutions. I think this pull request is ready for another review.

JustForFun88 avatar Dec 14 '22 18:12 JustForFun88

Where is the CharBuffer from (and why)?

panekj avatar Dec 14 '22 20:12 panekj

Where is the CharBuffer from (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.

JustForFun88 avatar Dec 15 '22 02:12 JustForFun88

Is there anything left to do?

panekj avatar Jan 27 '23 21:01 panekj

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.

JustForFun88 avatar Feb 02 '23 05:02 JustForFun88