Conversation
We factor out repeated boilerplate in the generated TypeScript de/serialization code into shared runtime helpers, reducing generated code size and fixing a couple of genuinely redundant computations. JSON parsing: * checkIsIterable(jsonable) replaces the null/typeof/Symbol.iterator checks that were duplicated at every list-typed property setter. * checkIsJsonObject(jsonable) replaces the null/Array.isArray/typeof checks duplicated at every concrete class's and interface's fromJsonable function. * checkModelType(modelType, expected) replaces the required/mismatch check duplicated once per class with a model type. XML serialization: * writeVElement/writeClassElement push directly into the shared `parts` array instead of each call site inlining openTag/content/closeTag, without introducing any extra string concatenation or array allocation compared to the original code. XML parsing: * nextPropertyOpenTag(cursor, className) replaces the ~25-line token-read/end-of-stream/close-tag/wrong-token-kind/namespace-check preamble that was duplicated in every class's property-parsing loop. It returns the token, `null`, or a DeserializationError directly, so it adds no allocation over the original inlined code despite running once per property parsed, not just once per instance. * Property close-tag consumption now reuses the already-computed `propertyLocalName` instead of redundantly recomputing `localNameOfTag(propertyStartTag.tag)`.
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.
We factor out repeated boilerplate in the generated TypeScript de/serialization code into shared runtime helpers, reducing generated code size and fixing a couple of genuinely redundant computations.
JSON parsing:
XML serialization:
partsarray instead of each call site inlining openTag/content/closeTag, without introducing any extra string concatenation or array allocation compared to the original code.XML parsing:
null, or a DeserializationError directly, so it adds no allocation over the original inlined code despite running once per property parsed, not just once per instance.propertyLocalNameinstead of redundantly recomputinglocalNameOfTag(propertyStartTag.tag).