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

Use String#replace whenever possible #1045

Merged
merged 2 commits into from
Dec 22, 2023
Merged

Conversation

snuyanzin
Copy link
Collaborator

If there is no need to replace by regexp then there is String#replace which is much faster than replaceAll, thus it's better to use it instead

Copy link

what-the-diff bot commented Dec 22, 2023

PR Summary

  • Updated Code in Code.java
    The import of Pattern has been removed and the certain field HYPHEN has been simplified with a straightforward call to replace("-").

  • Changes in Internet.java
    Pattern import was eliminated and the SINGLE_QUOTE field was replaced with a more straightforward replace("'") function. Additionally, a new Name object is being instantiated for cleaner and safer access to the firstName and lastName functions of faker.name().

  • Update in Helper Class FakeValuesService.java
    The method replaceAll is replaced with a simpler replace method, which should keep its functionality intact while simplifying the code and potentially improving performance.

  • Improvements in FinanceTest.java
    The replaceAll method has been replaced with a replace method. This is more straightforward and could possibly improve the speed of tests, without altering their actual output or their usefulness for QA purposes.

  • Modifications in ProviderGenerator.java
    The replaceAll call has been replaced with a replace command to simplify the code without changing its output or functionality. This may possibly improve the performance of the program.

@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8cc9d6c) 92.23% compared to head (9b7db13) 92.32%.
Report is 20 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1045      +/-   ##
============================================
+ Coverage     92.23%   92.32%   +0.08%     
- Complexity     2764     2767       +3     
============================================
  Files           291      291              
  Lines          5541     5540       -1     
  Branches        600      600              
============================================
+ Hits           5111     5115       +4     
+ Misses          274      272       -2     
+ Partials        156      153       -3     

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

@@ -91,7 +91,7 @@ public String domainName() {
}

public String domainWord() {
return FakerIDN.toASCII(SINGLE_QUOTE.matcher(faker.name().lastName().toLowerCase()).replaceAll(""));
return FakerIDN.toASCII(faker.name().lastName().toLowerCase().replace("'", ""));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't lowercase here at least use Locale.ROOT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here it's name generated base on locale set by user, so in case it iis e.g. TR it should be being lower cased to turkish lowercase. Thus i think here it is ok to have locale from faker's context

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it using fakers context when not passed though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, good catch,
added locale from context
thanks

@@ -145,7 +145,7 @@ public String webdomain() {
"www",
".",
FakerIDN.toASCII(
SINGLE_QUOTE.matcher(faker.name().firstName().toLowerCase()).replaceAll("") +
faker.name().firstName().toLowerCase().replace("'", "") +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also added locale from context

@kingthorin kingthorin merged commit 96dc71c into datafaker-net:main Dec 22, 2023
7 checks passed
@kingthorin
Copy link
Collaborator

Thanks!

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.

3 participants