julianandrews / sgf-parse

SGF parsing library for Rust.
MIT License
13 stars 3 forks source link

See about optimizing `SgfNodeBuilder` conversions #14

Closed julianandrews closed 3 years ago

julianandrews commented 3 years ago

Currently SgfNode.into_builder is a recursive function call (see #11), and SgfNodeBuilder.build has a bunch of Rc overhead and logic.

In principle SgfNode.into_builder should be possible to with operation at all (with a little tweaking to ensure the memory layout is the same), and the other direction (SgfNodeBuilder.build) could be zero-copy (though we'd still need to walk through and validate).

If conversion between the two were costless, I could move the SgfNode::new logic into SgfNodeBuilder.build, and then SgfNode::new would just call that.

julianandrews commented 3 years ago

Working on v3.0 I've decided to do away with the builder entirely.

Any constructible SgfNode will be serializable, and there will be a validate method which checks for validity. This way, users of the library can decide how they want to handle invalid (but still parseable/serializable) data.