Просмотр исходного кода

raft : Write compact if statements

nilsocket 6 лет назад
Родитель
Сommit
18a077d3d3
1 измененных файлов с 2 добавлено и 4 удалено
  1. 2 4
      raft/log_unstable.go

+ 2 - 4
raft/log_unstable.go

@@ -55,10 +55,7 @@ func (u *unstable) maybeLastIndex() (uint64, bool) {
 // is any.
 func (u *unstable) maybeTerm(i uint64) (uint64, bool) {
 	if i < u.offset {
-		if u.snapshot == nil {
-			return 0, false
-		}
-		if u.snapshot.Metadata.Index == i {
+		if u.snapshot != nil && u.snapshot.Metadata.Index == i {
 			return u.snapshot.Metadata.Term, true
 		}
 		return 0, false
@@ -71,6 +68,7 @@ func (u *unstable) maybeTerm(i uint64) (uint64, bool) {
 	if i > last {
 		return 0, false
 	}
+
 	return u.entries[i-u.offset].Term, true
 }