kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
319 stars 208 forks source link

Use better API for string comparison #441

Closed fazledyn-or closed 10 months ago

fazledyn-or commented 11 months ago

Description

While triaging your project, our bug fixing tool generated the following message-

In file: names_match.go, there is a function namesMatch that performs a case insensitive String equality check. String comparison with strings.ToLower or strings.ToUpper is significantly more expensive. For example, strings.ToLower will have to allocate memory for the new strings, and then convert the string to lower case. It is better to do the case insensitive equality check using the EqualFold function. This function does not need to create two intermediate strings and can return as soon as the first non-matching character has been found. iCR fixed the issue by introducing the strings.EqualFold function.

As a performance upgrade, I've replaced the string comparison using the EqualFold method.

CLA Requirements

This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.

All contributed commits are already automatically signed off.

The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin (see https://developercertificate.org/ for more information).

- Git Commit SignOff documentation

Sponsorship and Support

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed – to improve global software supply chain security.

The bug is found by running the Intelligent Code Repair (iCR) tool by OpenRefactory and then manually triaging the results.


P.S: This PR is NOT generated by a bot.

k8s-ci-robot commented 11 months ago

Welcome @fazledyn-or!

It looks like this is your first PR to kubernetes/kube-openapi 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-openapi has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

Jefftree commented 10 months ago

Thanks! /lgtm /approve

k8s-ci-robot commented 10 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fazledyn-or, Jefftree

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[pkg/generators/rules/OWNERS](https://github.com/kubernetes/kube-openapi/blob/master/pkg/generators/rules/OWNERS)~~ [Jefftree] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment