Skip to content

Commit

Permalink
Refactor to use same variable in type switches
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Oct 2, 2023
1 parent f3fdb2d commit 2775ff5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -2838,15 +2838,15 @@ func (a *Array) setCallbackWithChild(i uint64, child Value, maxInlineSize uint64
}

// Verify retrieved element is either SlabIDStorable or Slab, with identical value ID.
switch x := storable.(type) {
switch storable := storable.(type) {
case SlabIDStorable:
sid := SlabID(x)
sid := SlabID(storable)
if !vid.equal(sid) {
return false, nil
}

case Slab:
sid := x.SlabID()
sid := storable.SlabID()
if !vid.equal(sid) {
return false, nil
}
Expand All @@ -2864,9 +2864,9 @@ func (a *Array) setCallbackWithChild(i uint64, child Value, maxInlineSize uint64

// Verify overwritten storable has identical value ID.

switch x := existingValueStorable.(type) {
switch existingValueStorable := existingValueStorable.(type) {
case SlabIDStorable:
sid := SlabID(x)
sid := SlabID(existingValueStorable)
if !vid.equal(sid) {
return false, NewFatalError(
fmt.Errorf(
Expand All @@ -2876,7 +2876,7 @@ func (a *Array) setCallbackWithChild(i uint64, child Value, maxInlineSize uint64
}

case Slab:
sid := x.SlabID()
sid := existingValueStorable.SlabID()
if !vid.equal(sid) {
return false, NewFatalError(
fmt.Errorf(
Expand Down
12 changes: 6 additions & 6 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4717,15 +4717,15 @@ func (m *OrderedMap) setCallbackWithChild(
}

// Verify retrieved element value is either SlabIDStorable or Slab, with identical value ID.
switch x := valueStorable.(type) {
switch valueStorable := valueStorable.(type) {
case SlabIDStorable:
sid := SlabID(x)
sid := SlabID(valueStorable)
if !vid.equal(sid) {
return false, nil
}

case Slab:
sid := x.SlabID()
sid := valueStorable.SlabID()
if !vid.equal(sid) {
return false, nil
}
Expand All @@ -4743,9 +4743,9 @@ func (m *OrderedMap) setCallbackWithChild(

// Verify overwritten storable has identical value ID.

switch x := existingValueStorable.(type) {
switch existingValueStorable := existingValueStorable.(type) {
case SlabIDStorable:
sid := SlabID(x)
sid := SlabID(existingValueStorable)
if !vid.equal(sid) {
return false, NewFatalError(
fmt.Errorf(
Expand All @@ -4755,7 +4755,7 @@ func (m *OrderedMap) setCallbackWithChild(
}

case Slab:
sid := x.SlabID()
sid := existingValueStorable.SlabID()
if !vid.equal(sid) {
return false, NewFatalError(
fmt.Errorf(
Expand Down

0 comments on commit 2775ff5

Please sign in to comment.