-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm not sure if there's a name for this way of grouping methods, but the end result is dotted.Access.Patterns, and it's kinda nice. This was extensively discussed in the PR: #49 (comment) #49 (comment) #49 (comment) The "inlinability_test.go" file can be compiled with special flags (described in the comment at the top of the file) to see the outcome in assembly. Result? Yep, things are still inlinable; this change is performance neutral.
- Loading branch information
Showing
3 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Compile with '-gcflags -S' and grep the assembly for `"".Test`. | ||
// You'll find that both methods produce identical bodies modulo line numbers. | ||
package inlinability | ||
|
||
import ( | ||
"testing" | ||
|
||
ipld "github.com/ipld/go-ipld-prime" | ||
basicnode "github.com/ipld/go-ipld-prime/node/basic" | ||
) | ||
|
||
var sink ipld.NodeBuilder | ||
|
||
func TestStructReference(t *testing.T) { | ||
nb := basicnode.Style__String{}.NewBuilder() | ||
sink = nb | ||
} | ||
|
||
func TestVarReference(t *testing.T) { | ||
nb := basicnode.Style.String.NewBuilder() | ||
sink = nb | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package basicnode | ||
|
||
// Style embeds a NodeStyle for every kind of Node implementation in this package. | ||
// You can use it like this: | ||
// | ||
// basicnode.Style.Map.NewBuilder().BeginMap() //... | ||
// | ||
// and: | ||
// | ||
// basicnode.Style.String.NewBuilder().AssignString("x") // ... | ||
// | ||
// Most of the styles here are for one particular Kind of node (e.g. string, int, etc); | ||
// you can use the "Any" style if you want a builder that can accept any kind of data. | ||
var Style style | ||
|
||
type style struct { | ||
Any Style__Any | ||
Map Style__Map | ||
List Style__List | ||
Bool Style__Bool | ||
Int Style__Int | ||
Float Style__Float | ||
String Style__String | ||
Bytes Style__Bytes | ||
Link Style__Link | ||
} |