Skip to content

Commit

Permalink
Only deepcopy when required
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed May 11, 2024
1 parent e18ef30 commit 816d051
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (m *memory) CreatePrefix(_ context.Context, prefix Prefix, namespace string
if ok {
return Prefix{}, fmt.Errorf("prefix already created:%v", prefix)
}
m.prefixes[namespace][prefix.Cidr] = *prefix.deepCopy()
m.prefixes[namespace][prefix.Cidr] = prefix
return prefix, nil
}
func (m *memory) ReadPrefix(_ context.Context, prefix, namespace string) (Prefix, error) {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (m *memory) UpdatePrefix(_ context.Context, prefix Prefix, namespace string
if oldPrefix.version != oldVersion {
return Prefix{}, fmt.Errorf("%w: unable to update prefix:%s", ErrOptimisticLockError, prefix.Cidr)
}
m.prefixes[namespace][prefix.Cidr] = *prefix.deepCopy()
m.prefixes[namespace][prefix.Cidr] = prefix
return prefix, nil
}
func (m *memory) DeletePrefix(_ context.Context, prefix Prefix, namespace string) (Prefix, error) {
Expand All @@ -117,7 +117,7 @@ func (m *memory) DeletePrefix(_ context.Context, prefix Prefix, namespace string
return Prefix{}, ErrNamespaceDoesNotExist
}
delete(m.prefixes[namespace], prefix.Cidr)
return *prefix.deepCopy(), nil
return prefix, nil
}

func (m *memory) CreateNamespace(_ context.Context, namespace string) error {
Expand Down

0 comments on commit 816d051

Please sign in to comment.