Skip to content
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

Unnecessarily Cloning, structuring #1905

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

sharma-shray
Copy link
Contributor

Hello, minor updates, unnecessarily cloning, structuring

Copy link
Owner

@dandavison dandavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I like 3/5 of the changes, but would you mind reverting the other two?

@@ -79,7 +79,7 @@ pub fn set_options(
}
opt.navigate = opt.navigate || opt.env.navigate.is_some();
if opt.syntax_theme.is_none() {
opt.syntax_theme.clone_from(&opt.env.bat_theme);
opt.syntax_theme = opt.env.bat_theme.take();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While there might be an efficiency saving here, it makes the data inconsistent, so I think we should only make changes like that for demonstrated performance wins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i see, thanks

.get(2)
.or_else(|| captures.get(4))
.map_or("".to_string(), |m| m.as_str().to_string());
(key, value)
Copy link
Owner

@dandavison dandavison Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind reverting this change? It loses the "joint distribution" of the data: i.e. it's not as obvious from the new code that, for example, they will either both be 0 or neither be 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, corrected

Comment on lines 236 to 244
let commit = caps.get(1).unwrap().as_str();
let author = caps.get(2).unwrap().as_str();
let timestamp = caps.get(3).unwrap().as_str();
let commit = caps.get(1)?.as_str();
let author = caps.get(2)?.as_str();
let timestamp = caps.get(3)?.as_str();

let time = DateTime::parse_from_str(timestamp, timestamp_format).ok()?;

let line_number = caps.get(4).unwrap().as_str().parse::<usize>().ok()?;
let line_number = caps.get(4)?.as_str().parse::<usize>().ok()?;

let code = caps.get(5).unwrap().as_str();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap() here is actually okay because the regex is know at compile time. If it is changed but not the corresponding code here then it should crash for the developer and not silently fail and return None.
Similarly for the max line numbers above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap() here is actually okay because the regex is know at compile time. If it is changed but not the corresponding code here then it should crash for the developer and not silently fail and return None. Similarly for the max line numbers above.

should we reverting this changes?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think the only bit of the PR that arguably should be retained is not using else after the early return in src/align.rs -- I do slightly prefer that. But beyond that, there are lots of bugs and feature requests to work on if you've got time! And any performance improvements backed by profiling of course would be welcome.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create and tag issues as 🟣 good first issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, corrected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants