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

Fix performance and other issues reported by Codacy #4309

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

stweil
Copy link
Contributor

@stweil stweil commented Aug 26, 2024

  • replace std::string::substr by std::string::resize
  • initialize variables in initialization list
  • fix several format strings

This fixes two performance issues reported by Codacy:

    Ineffective call of function 'substr' because a prefix of the string
    is assigned to itself. Use resize() or pop_back() instead.

Signed-off-by: Stefan Weil <[email protected]>
This fixes several performance issues reported by Coverity:

    Variable 'master_trainer_' is assigned in constructor body.
    Consider performing initialization in initialization list.

Signed-off-by: Stefan Weil <[email protected]>
This fixes five performance issues reported by Codacy:

    %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.
    %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
    %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.

Signed-off-by: Stefan Weil <[email protected]>
@stweil stweil changed the title Fix performance issues reported by Codacy Fix performance and other issues reported by Codacy Aug 26, 2024
@egorpugin
Copy link
Contributor

I think it is possible to use in-class initializers instead of repeating vars in ctor.

struct x {
	int *ptr{};
};

Instead of x::x() : ptr{nullptr} {}

@egorpugin
Copy link
Contributor

Also it is 2025 soon, I would propose to allow some c++20/23 features.

What are tesseract compiler requirements?

Support ubuntu20.04 lts gcc?

@stweil stweil merged commit 027ad18 into tesseract-ocr:main Aug 26, 2024
7 checks passed
@stweil stweil deleted the codacy branch August 26, 2024 11:16
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