Skip to content

Commit

Permalink
Shorten max array lengths for the data type
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed May 3, 2020
1 parent e04f391 commit 81f2578
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (p *page) leafPageElements() []leafPageElement {
if p.count == 0 {
return nil
}
return (*[maxAllocSize]leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
const maxArraySize = maxAllocSize / unsafe.Sizeof(leafPageElement{})
return (*[maxArraySize]leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
unsafe.Sizeof(leafPageElement{}), 0))[:p.count:p.count]
}

Expand All @@ -79,7 +80,8 @@ func (p *page) branchPageElements() []branchPageElement {
if p.count == 0 {
return nil
}
return (*[maxAllocSize]branchPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
const maxArraySize = maxAllocSize / unsafe.Sizeof(branchPageElement{})
return (*[maxArraySize]branchPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
unsafe.Sizeof(branchPageElement{}), 0))[:p.count:p.count]
}

Expand Down

0 comments on commit 81f2578

Please sign in to comment.