mirror of
https://github.com/golang/go.git
synced 2025-10-19 19:13:18 +00:00
unicode/utf8: use builtin max function to simplify code
This commit is contained in:
parent
bdcd6d1b65
commit
202d498eb0
1 changed files with 2 additions and 8 deletions
|
@ -263,10 +263,7 @@ func DecodeLastRune(p []byte) (r rune, size int) {
|
||||||
// guard against O(n^2) behavior when traversing
|
// guard against O(n^2) behavior when traversing
|
||||||
// backwards through strings with long sequences of
|
// backwards through strings with long sequences of
|
||||||
// invalid UTF-8.
|
// invalid UTF-8.
|
||||||
lim := end - UTFMax
|
lim := max(end - UTFMax, 0)
|
||||||
if lim < 0 {
|
|
||||||
lim = 0
|
|
||||||
}
|
|
||||||
for start--; start >= lim; start-- {
|
for start--; start >= lim; start-- {
|
||||||
if RuneStart(p[start]) {
|
if RuneStart(p[start]) {
|
||||||
break
|
break
|
||||||
|
@ -303,10 +300,7 @@ func DecodeLastRuneInString(s string) (r rune, size int) {
|
||||||
// guard against O(n^2) behavior when traversing
|
// guard against O(n^2) behavior when traversing
|
||||||
// backwards through strings with long sequences of
|
// backwards through strings with long sequences of
|
||||||
// invalid UTF-8.
|
// invalid UTF-8.
|
||||||
lim := end - UTFMax
|
lim := max(end - UTFMax, 0)
|
||||||
if lim < 0 {
|
|
||||||
lim = 0
|
|
||||||
}
|
|
||||||
for start--; start >= lim; start-- {
|
for start--; start >= lim; start-- {
|
||||||
if RuneStart(s[start]) {
|
if RuneStart(s[start]) {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue