Closed wjdwndud0114 closed 9 months ago
Very nice, thanks for the PR! I'm on vacation right now, and will review in detail when I'm back. One thing I noticed that you could improve is that right now, extract_filepath
always allocates, even if there are no escape codes. You could change it to return a Cow<str>
. Then, when there are no escape codes in the string, you can just return a Cow::Borrowed
.
Thank you for the suggestion! This is my first time using Rust and used a lot of chatGPT so there are probably a lot of holes.
Looked into Cow
concept, but I think since we are doing a to_lowercase
or essentially to_ascii_lowercase
for each char, it always allocates? Or would a check for ascii char help before doing the to_ascii_lowercase
to keep track of if there was an lowercase mutation?
I could also just add a specific case for my rg
usage which is check if the input starts with the color code and extract until the next color code, but that's probably be too specific.
Right, that's a good point about to_lowercase
and always allocating. I'm going to merge this as-is and iterate a bit to see if I can incorporate the Cow
. I also want to add some tests and possibly benchmarks, I'll ping you when I add my changes 🙂
For live grep, I use rg like:
rg --column --line-number --no-heading --color=always --smart-case -- <query>
which has color.Added logic to grab the path for the icon while filtering out the ASCII color codes and keeping everything performant.