Skip to content

craft-dxf: faster ASCII writing and parse_recovering (ports of open CADCraft PRs) - #924

Merged
dylanmtaylor merged 3 commits into
mainfrom
craft-dxf/write-fast-path
Nov 11, 2026
Merged

dylanmtaylor merged 3 commits into
mainfrom
craft-dxf/write-fast-path

Conversation

@dylanmtaylor

Copy link
Copy Markdown
Member

Two changes to the tag layer of craft-dxf, ported from open CADCraft pull requests so they are not lost when CADCraft drops its own copy of the crate (storytold/cadcraft#3040). Part of #778.

Writing: no formatting machinery for codes, reals and plain text

Ported from storytold/cadcraft#1938 by @francescoBV (the crates/dxf part; the rest of that PR is CADCraft's own writer).

write_ascii and its code page forms wrote every group code through write!("{:>3}"), every real through a String of its own and every string one character at a time. Codes 0 to 9999 and reals are now appended in place, and text with no line break or backslash that is ASCII (or goes out as UTF-8) is copied as it is.

Adapted to this crate as it is now: the writer produces bytes, reals keep the exponent form added in #847, and text written in a code page still takes the long path, because a code page may write an ASCII character another way. The output is byte for byte what it was; fast_code_and_real_formatting_match_format compares codes, reals and strings with the old formatting, including a code page that shadows ASCII.

Reading: parse_recovering

Ported from storytold/cadcraft#1565 by @aljormon84 (the crates/dxf part; the clipping feature stays in CADCraft).

parse fails a file at the first line that is no group code and at a last group code with no value. parse_recovering returns the tags before that point and the 1-based line where reading stopped (None for an intact file).

Two differences from the source PR:

  • It stops at the damage. The source skipped the bad line and went on pairing lines, which reads values as group codes once a single line is missing. VectorCraft's own reader stops and reports the line; this does the same, so VectorCraft can use it.
  • It keeps the limits: the group-code count is checked before the text is decoded, and the tag list is reserved with an allocation that can fail, as in parse.

section_slices now ends a section at 0 EOF as well as 0 ENDSEC, so the EOF of a file cut inside a section is not one of its records.

Ran

  • cargo fmt -p craft-dxf --check: clean
  • cargo clippy -p craft-dxf --all-targets -- -D warnings: clean
  • cargo test -p craft-dxf: 84 passed, 2 ignored (11 test binaries), including the 5 new tests in tests/recovering.rs and the new unit test

Not run: any app against this branch, and no timing was measured here (the source PR's figures are for CADCraft's whole save path).

Not ported

storytold/cadcraft#1835 (TagStream, a streaming parser for the DWG bridge's output) is left for when the DWG bridge moves: it rewrites the binary reader this crate has since extended (R12 binary), and has no caller here yet.

francescoBV and others added 2 commits November 11, 2026 21:42
…achinery

write_ascii and its code page forms wrote every group code through
write!("{:>3}"), every real through a String of its own and every string
character by character. A large drawing writes millions of each. Codes 0 to
9999 and reals are now appended in place, and text with no line break or
backslash that is ASCII (or goes out as UTF-8) is copied as it is. Text for a
code page still takes the long path, since a code page may write an ASCII
character another way. The output is byte for byte what it was.

Ported from storytold/cadcraft#1938 (the crates/dxf part).
…he damage

parse fails a file at the first line that is no group code, and at a last
group code with no value. parse_recovering returns the tags before that point
and the line where reading stopped, so a caller can open what the file still
holds and say where it ends. Reading stops at the damage: lines after it are
not paired up by guesswork. Damage before the first group, a truncated binary
file and the group-code limit are still errors.

section_slices ends a section at EOF as well as ENDSEC, so the EOF of a file
cut inside a section is not one of that section's records.

Ported from storytold/cadcraft#1565 (the crates/dxf part).
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 44363b5 and 57db574.

Files selected for processing: 2

  • crates/dxf/src/lib.rs
  • crates/dxf/tests/recovering.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dylanmtaylor
dylanmtaylor merged commit 64a8c7f into main Nov 11, 2026
14 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants