Skip to content

Commit 088c5c7

Browse files
committed
simplify the loop logic
1 parent 8bb0ce0 commit 088c5c7

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

core/state/snapshot/snapshot.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,12 @@ func (t *Tree) Snapshots(root common.Hash, limits int, nodisk bool) []Snapshot {
307307
t.lock.RLock()
308308
defer t.lock.RUnlock()
309309

310-
if limits == 0 {
311-
return nil
312-
}
313-
layer := t.layers[root]
314-
if layer == nil {
315-
return nil
316-
}
317310
var ret []Snapshot
318-
for {
311+
for layer := t.layers[root]; layer != nil && limits != 0; layer, limits = layer.Parent(), limits-1 {
319312
if _, isdisk := layer.(*diskLayer); isdisk && nodisk {
320313
break
321314
}
322315
ret = append(ret, layer)
323-
limits -= 1
324-
if limits == 0 {
325-
break
326-
}
327-
parent := layer.Parent()
328-
if parent == nil {
329-
break
330-
}
331-
layer = parent
332316
}
333317
return ret
334318
}

0 commit comments

Comments
 (0)