Skip to content

Commit

Permalink
Merge pull request #16 from joelrose/fix/allocation-json-deseralize
Browse files Browse the repository at this point in the history
fix: only allocate once
  • Loading branch information
joelrose authored Mar 15, 2023
2 parents f55eb58 + 045df0e commit e137c2d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func (s JSONSerializer) Serialize(ss *sessions.Session) ([]byte, error) {

// Deserialize back to map[string]interface{}.
func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error {
if ss.Values == nil {
ss.Values = make(map[interface{}]interface{})
}

m := make(map[string]interface{})
if err := json.Unmarshal(d, &m); err != nil {
return fmt.Errorf("json: deserializing session values: %v", err)
}

if ss.Values == nil {
ss.Values = make(map[interface{}]interface{}, len(m))
}

for k, v := range m {
ss.Values[k] = v
}
Expand Down

0 comments on commit e137c2d

Please sign in to comment.