Conversation
- Change key reading from batch processing to sequential processing - Replace List<TomlDottedKey> with stack-based TempList<T> to avoid heap allocations during TOML serialization - Fix resolver cache registration order: set formatter before marking as registered to prevent reading uninitialized formatter on concurrent access - Simplify CsTomlParser by removing intermediate state fields (comment, value, dottedKeys) and exposing reader directly to TomlDocument - Move table/array-of-tables node construction from TomlTable into TomlTableNode for per-key granularity
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses incorrect TomlDocument serialization for arrays of tables and refactors core parsing/writing infrastructure (reader, writer, and source generator) to support the updated serialization behavior and improve allocation patterns.
Changes:
- Fix array-of-tables serialization ordering/formatting in
TomlTable/TomlTableNodeand add targeted tests. - Refactor parsing to read dotted keys incrementally via
CsTomlReader/CsTomlParser(introducingReadKeyResult). - Introduce stack/temporary list utilities (
TempList,InlineArray4) and update writer call sites accordingly.
Reviewed changes
Copilot reviewed 36 out of 37 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/CsToml.Tests/TomlTest.cs | Adds v1.0.0 encode/decode roundtrip test for TomlDocument. |
| tests/CsToml.Tests/TomlDocumentExtensions.cs | Updates test-side TOML writer construction to new writer API/state tracking. |
| tests/CsToml.Tests/DefaultTest.cs | Adds regression tests for array-of-tables serialization and dotted-key inline-table serialization cases. |
| src/CsToml/Values/TomlTableNodeDictionary.cs | Refactors internal node dictionary implementation / enumeration details. |
| src/CsToml/Values/TomlTableNode.cs | Splits/clarifies node creation paths for key-values vs table headers vs array-of-tables headers. |
| src/CsToml/Values/TomlTable.cs | Reworks TOML emission logic, including array-of-tables handling and ordering. |
| src/CsToml/Values/TomlStringHelper.cs | Formatting/whitespace adjustments (no functional change apparent). |
| src/CsToml/Values/TomlString.GetValue.cs | Removes unused reflection import. |
| src/CsToml/Values/TomlString.cs | Adjusts escaping behavior and introduces unicode-escape helper for control/escape bytes. |
| src/CsToml/Values/TomlInlineTable.cs | Moves inline-table key stack tracking from List<> to TempList<>. |
| src/CsToml/Values/TomlDottedKeyHelper.cs | Updates primitive-key formatting to use new writer ctor/state stacks. |
| src/CsToml/Values/TomlDottedKey.cs | Updates dotted-key join formatting to use new writer ctor/state stacks. |
| src/CsToml/Values/TomlBoolean.cs | Simplifies bool formatting logic in TryFormat. |
| src/CsToml/Utility/Utf8Writer.cs | Formatting-only change (removes unused/extra leading lines). |
| src/CsToml/Utility/TempList.cs | Introduces temporary stack/list structure used by writer and serializers. |
| src/CsToml/Utility/InlineArray.cs | Adds InlineArray4<T> polyfill for pre-.NET 10 targets. |
| src/CsToml/Utility/ExtendableArray.cs | Adds writable-span accessor used during ordering/rewrite steps. |
| src/CsToml/Utility/ByteSequenceSegment.cs | Formatting-only change (removes unused/extra leading lines). |
| src/CsToml/Utility/ByteBufferSegmentWriter.cs | Formatting-only change (removes unused System import). |
| src/CsToml/Utf8TomlDocumentWriter.cs | Refactors writer state tracking to use TempList<> and adds bare-key writing path. |
| src/CsToml/TomlNamingConvention.cs | Formatting-only (adds BOM/normalizes indentation). |
| src/CsToml/TomlDocumentNode.cs | Removes unused imports / trims comment on enumerator. |
| src/CsToml/TomlDocument.cs | Refactors parsing loop to use new reader/key APIs and revised comment handling. |
| src/CsToml/TomlCodes.cs | Refactors escape-sequence switch handling (deduplication). |
| src/CsToml/Formatter/Resolver/TomlValueFormatterResolver.cs | Fixes registration flag set ordering. |
| src/CsToml/Formatter/Resolver/TomlSerializedObjectFormatterResolver.cs | Fixes registration flag set ordering in overloads. |
| src/CsToml/Formatter/Resolver/BuiltinFormatterResolver.cs | Formatting-only change (removes unused/extra leading lines). |
| src/CsToml/Extension/DateOnlyExtensions.cs | Formatting-only change (normalizes file structure). |
| src/CsToml/Extension/CollectionExtensions.cs | Removes stray blank line. |
| src/CsToml/Error/CsTomlException.cs | Formatting-only change (removes unused/extra leading lines). |
| src/CsToml/Debugger/TomlArrayDebugView.cs | Formatting-only change (removes trailing blank lines). |
| src/CsToml/CsTomlSerializer.cs | Updates serializer to construct writer with explicit key/state stacks. |
| src/CsToml/CsTomlReader.cs | Adds ReadKeyResult, refactors key parsing and inline-table parsing to new incremental key API. |
| src/CsToml/CsTomlParser.cs | Refactors parser to a lighter state machine and defers key/value parsing to CsTomlReader. |
| src/CsToml.Generator/TomlKeyTypeMatcher.cs | Adds bare-key detection helper for generator-emitted writer calls. |
| src/CsToml.Generator/Internal/Polyfill/IsExternalInit.cs | Converts to file-scoped namespace formatting. |
| src/CsToml.Generator/Generator.cs | Emits bare-key write calls when possible and aligns generator output with writer changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes
TomlDocumentserialization for array of tables and includes related refactoring of writer/reader/source generator.