Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
580049db
Commit
580049db
authored
Jan 18, 2017
by
Brian Atkinson
Committed by
Dylan Trotter
Jan 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make newDictTable able to be inlined. (#148)
parent
0d83793a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
runtime/dict.go
runtime/dict.go
+12
-5
No files found.
runtime/dict.go
View file @
580049db
...
...
@@ -65,11 +65,18 @@ type dictTable struct {
// newDictTable allocates a table where at least minCapacity entries can be
// accommodated. minCapacity must be <= maxDictSize.
func
newDictTable
(
minCapacity
int
)
*
dictTable
{
numEntries
:=
minDictSize
for
numEntries
<
minCapacity
{
numEntries
<<=
1
}
return
&
dictTable
{
entries
:
make
([]
*
dictEntry
,
numEntries
)}
// This takes the given capacity and sets all bits less than the highest bit.
// Adding 1 to that value causes the number to become a multiple of 2 again.
// The minDictSize is mixed in to make sure the resulting value is at least
// that big. This implementation makes the function able to be inlined, as
// well as allows for complete evaluation of constants at compile time.
numEntries
:=
(
minDictSize
-
1
)
|
minCapacity
numEntries
|=
numEntries
>>
1
numEntries
|=
numEntries
>>
2
numEntries
|=
numEntries
>>
4
numEntries
|=
numEntries
>>
8
numEntries
|=
numEntries
>>
16
return
&
dictTable
{
entries
:
make
([]
*
dictEntry
,
numEntries
+
1
)}
}
// loadEntry atomically loads the i'th entry in t and returns it.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment