Skip to content

Fix TomlDocument serialization for array of tables and refactoring - #107

Merged
prozolic merged 7 commits into
mainfrom
refactor
Jun 25, 2026
Merged

Fix TomlDocument serialization for array of tables and refactoring#107
prozolic merged 7 commits into
mainfrom
refactor

Conversation

@prozolic

Copy link
Copy Markdown
Owner

This PR fixes TomlDocument serialization for array of tables and includes related refactoring of writer/reader/source generator.

prozolic added 6 commits June 7, 2026 23:49
- 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
Copilot AI review requested due to automatic review settings June 25, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / TomlTableNode and add targeted tests.
  • Refactor parsing to read dotted keys incrementally via CsTomlReader/CsTomlParser (introducing ReadKeyResult).
  • 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.

Comment thread src/CsToml/Utility/TempList.cs
Comment thread src/CsToml/Utf8TomlDocumentWriter.cs Outdated
Comment thread src/CsToml/Utility/InlineArray.cs
@prozolic
prozolic merged commit 877e6d5 into main Jun 25, 2026
1 check passed
@prozolic prozolic mentioned this pull request Jun 25, 2026
@prozolic
prozolic deleted the refactor branch June 25, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants