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

Replace substr with e.g. str_starts_with or str_ends_with where appropriate. #3196

Merged
merged 3 commits into from
Nov 9, 2023

Conversation

EreMaijala
Copy link
Contributor

@EreMaijala EreMaijala commented Nov 7, 2023

While profiling VuFind I noticed that there was a relatively high number of substr calls. While many of them are necessary, there was a lot of old code using them for comparison, so here's a bit cleanup. All tests are passing for me, but this was all manual work, so some scrutiny is welcome.

TODO

  • When merging, note removal of \VuFindSearch\Backend\EDS\SearchRequestModel::endsWith() in changelog

@EreMaijala EreMaijala requested a review from demiankatz November 7, 2023 13:22
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @EreMaijala, this makes a lot of code significantly more readable, in addition to improving efficiency. I just had a couple of questions and observations from my review....

module/VuFind/src/VuFind/Config/Upgrade.php Outdated Show resolved Hide resolved
@@ -1496,7 +1496,7 @@ protected function extractComments($filename)
// Is the current line a setting? If so, add to the return value:
$set = trim(substr($trimmed, 0, $equals));
$set = trim(str_replace('[]', '', $set));
if (!empty($section) && !empty($set)) {
if ('' == $section && '' == $set) {
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be reversing the logic. If this didn't cause a test to fail, maybe we'd better add another test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, fixed! It'd only affect inline comments, but yes, not caught by any test.

Copy link
Member

Choose a reason for hiding this comment

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

I've just pushed up a test to cover this code, and confirmed that it failed before your fix and passes after.

module/VuFind/src/VuFind/ILS/Driver/NoILS.php Show resolved Hide resolved
@EreMaijala EreMaijala requested a review from demiankatz November 9, 2023 07:29
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Looks good to me now -- thanks again, @EreMaijala!

@demiankatz demiankatz merged commit 33d4a14 into vufind-org:dev Nov 9, 2023
6 checks passed
@demiankatz demiankatz deleted the dev-substr-cleanup branch November 9, 2023 12:10
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.

2 participants