airbnb / airbnb/DeepLinkDispatch
performance issue: containsInvalidHostnameAsciiCodes
- Dominant language
- Kotlin
- Stars
- 4.4k
- Forks
- 414
- PR merge metrics
- No merged PRs in 30d
Description
Original code:
```java
private static boolean containsInvalidHostnameAsciiCodes(String hostnameAscii) {
for (int i = 0; i < hostnameAscii.length(); i++) {
char c = hostnameAscii.charAt(i);
// The WHATWG Host parsing rules accepts some character codes which are invalid by
// definition for OkHttp's host header checks (and the WHATWG Host syntax definition). Here
// we rule out characters that would cause problems in host headers.
if (c <= '\u001f' || c >= '\u007f') {
return true;
}
// Check for the characters mentioned in the WHATWG Host parsing spec:
// U+0000, U+0009, U+000A, U+000D, U+0020, "#", "%", "/", ":", "?", "@", "[", "\", and "]"
// (excluding the characters covered above).
if (" #%/:?@[\\]".indexOf(c) != -1) {
return true;
}
}
return false;
}
```
line with IndexOf call is not optimal.

Contributor guide
Research direction
Locate containsInvalidHostnameAsciiCodes and inspect its callers and any existing tests. Focus on the line using indexOf, preserving the hostname character checks while addressing the reported performance concern; the work is done when the method behaves identically with a more efficient check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100