Skip to content

Commit

Permalink
refactor: create 1 decoder instance per package
Browse files Browse the repository at this point in the history
This has no logic implications, but it feels like multiple instances are unnecessary
  • Loading branch information
bevzzz committed Feb 26, 2024
1 parent e207fd5 commit 8371047
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions schema/v3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
)

func init() {
decode.RegisterDecoder(schema.Version{Major: 3, Minor: 0}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 2, Minor: 0}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 1, Minor: 0}, new(decoder))
d := new(decoder)
decode.RegisterDecoder(schema.Version{Major: 3, Minor: 0}, d)
decode.RegisterDecoder(schema.Version{Major: 2, Minor: 0}, d)
decode.RegisterDecoder(schema.Version{Major: 1, Minor: 0}, d)
}

// decoder decodes cell contents and metadata for nbformat v3.0, v2.0, and v1.0.
Expand Down
13 changes: 7 additions & 6 deletions schema/v4/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
)

func init() {
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 5}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 4}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 3}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 2}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 1}, new(decoder))
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 0}, new(decoder))
d := new(decoder)
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 5}, d)
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 4}, d)
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 3}, d)
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 2}, d)
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 1}, d)
decode.RegisterDecoder(schema.Version{Major: 4, Minor: 0}, d)
}

// decoder decodes cell contents and metadata for nbformat v4.0.
Expand Down

0 comments on commit 8371047

Please sign in to comment.