Skip to content

Commit 1e92ff1

Browse files
callthingsoffgopherbot
authored andcommitted
unicode/utf8: use builtin max function to simplify code
Change-Id: I6a73b645d074baaa4d09480bdf4192816a8c2450 GitHub-Last-Rev: 202d498 GitHub-Pull-Request: #71945 Reviewed-on: https://go-review.googlesource.com/c/go/+/652177 Auto-Submit: Keith Randall <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent c441eec commit 1e92ff1

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Diff for: src/unicode/utf8/utf8.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,7 @@ func DecodeLastRune(p []byte) (r rune, size int) {
263263
// guard against O(n^2) behavior when traversing
264264
// backwards through strings with long sequences of
265265
// invalid UTF-8.
266-
lim := end - UTFMax
267-
if lim < 0 {
268-
lim = 0
269-
}
266+
lim := max(end - UTFMax, 0)
270267
for start--; start >= lim; start-- {
271268
if RuneStart(p[start]) {
272269
break
@@ -303,10 +300,7 @@ func DecodeLastRuneInString(s string) (r rune, size int) {
303300
// guard against O(n^2) behavior when traversing
304301
// backwards through strings with long sequences of
305302
// invalid UTF-8.
306-
lim := end - UTFMax
307-
if lim < 0 {
308-
lim = 0
309-
}
303+
lim := max(end - UTFMax, 0)
310304
for start--; start >= lim; start-- {
311305
if RuneStart(s[start]) {
312306
break

0 commit comments

Comments
 (0)