Further reduce redundant setup.
In the process, noticed we're using the test subject nodebuilder for
part of the selector setup too... which is... well, it's not wrong,
per se, but it's certainly tangental.  I don't see any good way to
avoid it though, so, there's now just a comment about this fact.
@@ -14,11 +14,23 @@ import (
"github.com/ipld/go-ipld-prime/traversal/selector"
)
-func SpecBenchmarkWalkMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) {
- n := must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(corpus.Map3StrInt()))))
- seldefn := must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(`{"a":{">":{".":{}}}}`))))
+func mustNodeFromJsonString(nb ipld.NodeBuilder, str string) ipld.Node {
+ return must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(str))))
+}
+func mustSelectorFromJsonString(nb ipld.NodeBuilder, str string) selector.Selector {
+ // Needing an 'nb' parameter here is sort of off-topic, to be honest.
+ // Someday the selector package will probably contain codegen'd nodes of its own schema, and we'll use those unconditionally.
+ // For now... we'll just use whatever node you're already testing, because it oughta work
+ // (and because it avoids hardcoding any other implementation that might cause import cycle funtimes.).
+ seldefn := mustNodeFromJsonString(nb, str)
sel, err := selector.ParseSelector(seldefn)
must.NotError(err)
+ return sel
+}
+
+func SpecBenchmarkWalkMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) {
+ n := mustNodeFromJsonString(nb, corpus.Map3StrInt())
+ sel := mustSelectorFromJsonString(nb, `{"a":{">":{".":{}}}}`)
b.ResetTimer()
var visitCountSanityCheck int
