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

Optimize findBetween method (remove calling function mb_substr()) #20059

Merged

Conversation

salehhashemi1992
Copy link
Contributor

Utilising mb_strrpos with an offset instead of calling the mb_substr() Call.

Copy link

what-the-diff bot commented Nov 1, 2023

PR Summary

  • Improvement in 'findBetween' method in 'BaseStringHelper.php'
    • The existing code in this method was edited to enhance efficiency and readability.
      • Instead of using the variable '$subString', the function 'mb_substr' is now applied directly to the string, simplifying and cleaning up the code.
      • The positions specifying the string segment to be returned have been recalculated for better precision. 'startPos' now includes the length of 'start' to properly determine the beginning of the required segment. Similarly, 'endPos' utilizes '$string' instead of the removed '$subString'.
      • The modified returned value now benefits from 'mb_substr' applied on '$string', enhancing the precision.
    • This streamlined approach not only makes the code easier to understand but also optimizes the program's use of resources by reducing unnecessary variables.

Copy link

codecov bot commented Nov 1, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6804fbe) 46.70% compared to head (5ce3b4e) 48.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20059      +/-   ##
==========================================
+ Coverage   46.70%   48.01%   +1.30%     
==========================================
  Files         445      445              
  Lines       43896    43896              
==========================================
+ Hits        20503    21078     +575     
+ Misses      23393    22818     -575     
Files Coverage Δ
framework/helpers/BaseStringHelper.php 99.44% <100.00%> (ø)

... and 13 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@salehhashemi1992 salehhashemi1992 changed the title Optimize findBetween method to remove calling function mb_substr() Optimize findBetween method (remove calling function mb_substr()) Nov 1, 2023
@salehhashemi1992 salehhashemi1992 marked this pull request as ready for review November 1, 2023 11:42
@bizley bizley added this to the 2.0.50 milestone Nov 2, 2023
@bizley bizley merged commit 11c80bf into yiisoft:master Nov 2, 2023
49 checks passed
@salehhashemi1992 salehhashemi1992 deleted the feature/optimize-findBetween-method branch November 2, 2023 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants