Skip to content

replace null literals with nullptr and optimize setidentity with std::fill#26882

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
shyama7004:nullptr-setidentity
Feb 7, 2025
Merged

replace null literals with nullptr and optimize setidentity with std::fill#26882
asmorkalov merged 1 commit intoopencv:4.xfrom
shyama7004:nullptr-setidentity

Conversation

@shyama7004
Copy link
Copy Markdown
Contributor

@shyama7004 shyama7004 commented Feb 6, 2025

  • Replaced 0 and NULL with nullptr in hconcat and vconcat for better type safety.
  • Optimized cv::setIdentity() for CV_64FC1 by using std::fill to zero rows and setting diagonals separately.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov
Copy link
Copy Markdown
Contributor

@shyama7004 Why do you think that the solution with std::fill is faster?

@shyama7004
Copy link
Copy Markdown
Contributor Author

@shyama7004 Why do you think that the solution with std::fill is faster?

std::fill avoids checking "if (j==i)" for every element by zeroing the entire row at once, reducing the number of branch checks.
Modern compilers can vectorize std::fill, so it runs faster than a loop with a conditional on each element.

@asmorkalov asmorkalov added category: core cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) labels Feb 7, 2025
@asmorkalov asmorkalov added this to the 4.12.0 milestone Feb 7, 2025
@asmorkalov asmorkalov self-requested a review February 7, 2025 12:02
@asmorkalov asmorkalov merged commit aeac913 into opencv:4.x Feb 7, 2025
25 of 28 checks passed
@shyama7004 shyama7004 deleted the nullptr-setidentity branch February 7, 2025 14:59
@asmorkalov asmorkalov mentioned this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: core cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants