Skip to content

Commit b72131c

Browse files
committed
合并两次b.Volume()为一次调用
合并两次b.Volume()为一次调用,培养注重效率的习惯,充分利用Go的if可设初始值的特性。
1 parent b7b712d commit b72131c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ebook/02.5.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ method的语法如下:
160160
v := 0.00
161161
k := Color(WHITE)
162162
for _, b := range bl {
163-
if b.Volume() > v {
164-
v = b.Volume()
163+
if bv := b.Volume(); bv > v {
164+
v = bv
165165
k = b.color
166166
}
167167
}

0 commit comments

Comments
 (0)