From 80ec22945a05052b4efade0bb1f7fa5a66b215fb Mon Sep 17 00:00:00 2001 From: alaningtrump Date: Fri, 3 Jul 2026 23:59:26 +0800 Subject: [PATCH] refactor: use the built-in max/min to simplify the code (#10657) Signed-off-by: alaningtrump --- pkg/functions/peg/parser.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/functions/peg/parser.go b/pkg/functions/peg/parser.go index a09f56171..52b890979 100644 --- a/pkg/functions/peg/parser.go +++ b/pkg/functions/peg/parser.go @@ -461,10 +461,7 @@ func (p *RuleParser) parse(arena *Arena, ctx *ParseContext, start int) ParseResu if result.Type != Fail { text := "" if result.Start < len(ctx.Input) { - end := result.End - if end > len(ctx.Input) { - end = len(ctx.Input) - } + end := min(result.End, len(ctx.Input)) text = ctx.Input[result.Start:end] } @@ -514,10 +511,7 @@ func (p *TagParser) parse(arena *Arena, ctx *ParseContext, start int) ParseResul if result.Type != Fail { text := "" if result.Start < len(ctx.Input) { - end := result.End - if end > len(ctx.Input) { - end = len(ctx.Input) - } + end := min(result.End, len(ctx.Input)) text = ctx.Input[result.Start:end] }