From fb022f54c074086fd6085cacd9731260089b8f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 17 May 2025 14:52:59 +0800 Subject: [PATCH] chore: longestCommonPrefix func in tree.go, fix variable name and add comment --- tree.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tree.go b/tree.go index 0d3e5a8c..ce469325 100644 --- a/tree.go +++ b/tree.go @@ -65,10 +65,12 @@ func (trees methodTrees) get(method string) *node { return nil } +// calculate the length of the longest common prefix of two strings func longestCommonPrefix(a, b string) int { i := 0 - max_ := min(len(a), len(b)) - for i < max_ && a[i] == b[i] { + // commonPrefixMaxLen is the min value of a and b's length. + commonPrefixMaxLen := min(len(a), len(b)) + for i < commonPrefixMaxLen && a[i] == b[i] { i++ } return i