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

avoid multiple charAt calls for injectedLogSite equals() #394

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

copybara-service[bot]
Copy link

avoid multiple charAt calls for injectedLogSite equals()

RELNOTES=n/a

RELNOTES=n/a
PiperOrigin-RevId: 700781918
@copybara-service copybara-service bot merged commit 7f14d9d into master Nov 27, 2024
@copybara-service copybara-service bot deleted the test_700422386 branch November 27, 2024 20:50
@hagbard
Copy link
Contributor

hagbard commented Nov 28, 2024

Since '.' == 2E and '/' == 2F, the test can be rewritten from:

        if (c1 != c2) {
          // If the characters are not equal, but the slash/dot difference is accounted for, then
          // consider them equivalent.
          if (!(c1 == '/' && c2 == '.') && !(c1 == '.' && c2 == '/')) {
            return false;
          }
        }

To:

        if (c1 != c2) {
          // Account for '.' (0x2E) and '/' (0x2F) being equivalent by using the fact they differ only in the lowest bit.
          if ((c1 & ~0x1) != 0x2E || (c1 ^ c2) != 0x1) {
            return false;
        }

And in the latter form the failure case if likely to be hit after a simpler test.

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