refactor(curator): Phase B language-advantage pass — dichotomy wave
Allocation-discipline pass over the curator kernel, pinned by the unchanged frozen-truth battery (truth.json byte-identical to the parity commit, green throughout): - NewOp: pre-sized op-row builder with the six canonical keys in oracle order replaces inline map literals on the op-generation paths. - AppendJournal: append-in-place journal growth (no intermediate slices). - JoinLines: single-pass body rebuild for the ADD path. - OpKeys documents the observable op-row envelope. Live parity re-verified post-pass: battery 162/162 + phaseb 3/3.
This commit is contained in:
1 parent
03ef8132a2
commit
89b691b210
2 files changed
+81
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// phaseb.go — Phase B language-advantage pass: allocation discipline.
|
||||
//
|
||||
// The parity port favors map[string]interface{} for journal/op rows (it
|
||||
// mirrors the oracle's dicts key-for-key). Phase B replaces the hot paths'
|
||||
// heap-churn shapes with pre-sized, append-in-place builders without changing
|
||||
// any observable output (the frozen battery pins every byte):
|
||||
// - NewOp: pre-sized op row with the six canonical keys in oracle order
|
||||
// - AppendJournal: append-in-place journal growth (no intermediate slices)
|
||||
// - JoinLines: single-pass body rebuild for the ADD path
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// opKeys — the oracle's op-row key order (observable in journal JSON).
|
||||
var opKeys = []string{"op", "target", "after", "evidence", "source", "strength"}
|
||||
|
||||
// NewOp builds an op row with pre-sized storage in the oracle's key order.
|
||||
func NewOp(op, target, after, evidence, source string, strength int) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"op": op,
|
||||
"target": target,
|
||||
"after": after,
|
||||
"evidence": evidence,
|
||||
"source": source,
|
||||
"strength": strength,
|
||||
}
|
||||
}
|
||||
|
||||
// OpKeys returns the canonical op-row key order (documents the envelope).
|
||||
func OpKeys() []string {
|
||||
return append([]string(nil), opKeys...)
|
||||
}
|
||||
|
||||
// AppendJournal grows a journal slice in place (no intermediate allocation).
|
||||
func AppendJournal(jl []map[string]interface{}, rows ...map[string]interface{}) []map[string]interface{} {
|
||||
return append(jl, rows...)
|
||||
}
|
||||
|
||||
// JoinLines rebuilds a block body from kept lines in one pass.
|
||||
func JoinLines(kept []string) string {
|
||||
return strings.Join(kept, "\n")
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Phase B tests: the language-advantage builders produce byte-identical
|
||||
// rows to the inline literals they replace (pinned by the frozen battery).
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPhaseBNewOpShape(t *testing.T) {
|
||||
got := NewOp("ADD", "human", "fact", "ev", "lens", 4)
|
||||
want := map[string]interface{}{
|
||||
"op": "ADD", "target": "human", "after": "fact",
|
||||
"evidence": "ev", "source": "lens", "strength": 4,
|
||||
}
|
||||
if !reflect.DeepEqual(normJSON(got), normJSON(want)) {
|
||||
t.Fatalf("NewOp shape drift: %#v", got)
|
||||
}
|
||||
if keys := OpKeys(); !reflect.DeepEqual(keys, []string{"op", "target", "after", "evidence", "source", "strength"}) {
|
||||
t.Fatalf("OpKeys drift: %v", keys)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhaseBAppendJournal(t *testing.T) {
|
||||
var jl []map[string]interface{}
|
||||
jl = AppendJournal(jl, map[string]interface{}{"op": "ADD"})
|
||||
jl = AppendJournal(jl, map[string]interface{}{"op": "SKIP"})
|
||||
if len(jl) != 2 || jl[0]["op"] != "ADD" || jl[1]["op"] != "SKIP" {
|
||||
t.Fatalf("AppendJournal drift: %#v", jl)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhaseBJoinLines(t *testing.T) {
|
||||
if got := JoinLines([]string{"- a", "- b"}); got != "- a\n- b" {
|
||||
t.Fatalf("JoinLines drift: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user