Skip to content

Commit

Permalink
Use defer for read mutex unlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 22, 2021
1 parent 330195b commit ba58bd5
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/trie/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,14 @@ func encodeChild(child node, buffer io.Writer) (err error) {
// specified at the top of this package.
func encodeLeaf(l *leaf, buffer io.Writer) (err error) {
l.encodingMu.RLock()
defer l.encodingMu.RUnlock()
if !l.dirty && l.encoding != nil {
_, err = buffer.Write(l.encoding)
l.encodingMu.RUnlock()
if err != nil {
return fmt.Errorf("cannot write stored encoding to buffer: %w", err)
}
return nil
}
l.encodingMu.RUnlock()

encoding, err := l.header()
if err != nil {
Expand Down

0 comments on commit ba58bd5

Please sign in to comment.