Skip to content

Commit

Permalink
Merge pull request square#5061 from yschimke/starts_with
Browse files Browse the repository at this point in the history
Use startsWith instead of regionMatches
  • Loading branch information
squarejesse authored May 18, 2019
2 parents dcf5c8c + 84be038 commit 6911181
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions okhttp/src/main/java/okhttp3/CertificatePinner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ data class CertificatePinner internal constructor(
if (pattern.startsWith(WILDCARD)) {
val firstDot = hostname.indexOf('.')
return hostname.length - firstDot - 1 == canonicalHostname.length &&
hostname.regionMatches(firstDot + 1, canonicalHostname, 0, canonicalHostname.length,
ignoreCase = false)
hostname.startsWith(canonicalHostname, ignoreCase = false, startIndex = firstDot + 1)
}
return hostname == canonicalHostname
}
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/java/okhttp3/HttpUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,10 @@ class HttpUrl internal constructor(builder: Builder) {
// Scheme.
val schemeDelimiterOffset = schemeDelimiterOffset(input, pos, limit)
if (schemeDelimiterOffset != -1) {
if (input.regionMatches(pos, "https:", 0, 6, ignoreCase = true)) {
if (input.startsWith("https:", ignoreCase = true, startIndex = pos)) {
this.scheme = "https"
pos += "https:".length
} else if (input.regionMatches(pos, "http:", 0, 5, ignoreCase = true)) {
} else if (input.startsWith("http:", ignoreCase = true, startIndex = pos)) {
this.scheme = "http"
pos += "http:".length
} else {
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/java/okhttp3/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ class Request internal constructor(
open fun url(url: String): Builder {
// Silently replace web socket URLs with HTTP URLs.
val finalUrl: String = when {
url.regionMatches(0, "ws:", 0, 3, ignoreCase = true) -> {
url.startsWith("ws:", ignoreCase = true) -> {
"http:${url.substring(3)}"
}
url.regionMatches(0, "wss:", 0, 4, ignoreCase = true) -> {
url.startsWith("wss:", ignoreCase = true) -> {
"https:${url.substring(4)}"
}
else -> url
Expand Down
6 changes: 3 additions & 3 deletions okhttp/src/main/java/okhttp3/internal/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ object Util {
if (b == address.size) return null // Too many groups.

// Read a delimiter.
if (i + 2 <= limit && input.regionMatches(i, "::", 0, 2)) {
if (i + 2 <= limit && input.startsWith("::", startIndex = i)) {
// Compression "::" delimiter, which is anywhere in the input, including its prefix.
if (compress != -1) return null // Multiple "::" delimiters.
i += 2
Expand All @@ -353,9 +353,9 @@ object Util {
if (i == limit) break
} else if (b != 0) {
// Group separator ":" delimiter.
if (input.regionMatches(i, ":", 0, 1)) {
if (input.startsWith(":", startIndex = i)) {
i++
} else if (input.regionMatches(i, ".", 0, 1)) {
} else if (input.startsWith(".", startIndex = i)) {
// If we see a '.', rewind to the beginning of the previous group and parse as IPv4.
if (!decodeIpv4Suffix(input, groupOffset, limit, address, b - 2)) return null
b += 2 // We rewound two bytes and then added four.
Expand Down

0 comments on commit 6911181

Please sign in to comment.