* Reduce marshal and unmarshal overhead
Targeted optimizations to reduce performance overhead introduced by
recent feature additions and the unsafe removal.
Unmarshal:
- parseKeyval: access the node directly in the builder's slice to set
Raw, bypassing NodeAt which triggers a GC write barrier for the
nodes-pointer on every key-value expression.
- Iterator.Next: cache the *nodes slice dereference in a local variable
to avoid repeated pointer-to-slice indirection in the hot loop.
Marshal:
- Guard shouldOmitZero calls with an inlineable options.omitzero check.
shouldOmitZero has inlining cost 1145 (budget 80), so avoiding the
function call when omitzero is not set removes per-field overhead.
- Inline the isNil check in encodeMap. isNil has inlining cost 93
(budget 80), so expanding it at the single hot call site avoids
per-map-entry function call overhead.
Update README benchmarks.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Removes all unsafe operations from go-toml, making the codebase
fully safe Go code. The internal/danger package that contained
unsafe operations has been deleted.
Changes:
- Replace pointer-based node navigation with index-based navigation
- Node.next and Node.child now store absolute indices into the
backing nodes slice instead of relative offsets
- Add nodes pointer to Node and Iterator for safe navigation
- Replace danger.TypeID with reflect.Type for cache keys
- Delete internal/danger package entirely
Performance overhead is under 10% compared to the unsafe version,
which is acceptable for the safety and maintainability benefits.
[Cursor][claude-sonnet-4-20250514]