Skip to content

Commit

Permalink
Avoid creating unnecessary intermediate strings (#3439)
Browse files Browse the repository at this point in the history
* Refactor JSON serialization to use MemoryStream

Replaced StringWriter with MemoryStream and StreamWriter for JSON serialization to improve efficiency. JsonWriter is now initialized with StreamWriter. Adjusted indentation levels in ProcessStructure and ProcessMembers methods. Final request content is now obtained as a byte array from MemoryStream.

* Update generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt

Co-authored-by: Stuart Lang <[email protected]>

* Update generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt

Co-authored-by: Stuart Lang <[email protected]>

* Simplify StreamWriter instantiation

Refactor the instantiation of the `StreamWriter` object within a `using` statement by removing unnecessary parameters. The original code included `null` for encoding, `-1` for buffer size, and `true` for leaving the stream open. The updated code uses the default constructor, which only requires the `MemoryStream` object, as the default behavior is sufficient for the intended use case.

* Add InvariantCultureStreamWriter for consistent formatting

Introduce InvariantCultureStreamWriter class to enforce invariant
culture formatting. Replace StreamWriter with
InvariantCultureStreamWriter in JsonRPCRequestMarshaller.tt to
ensure consistent JSON formatting regardless of system culture.

---------

Co-authored-by: Stuart Lang <[email protected]>
  • Loading branch information
paulomorgado and slang25 authored Aug 24, 2024
1 parent 7056953 commit 30f26e4
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 64 deletions.
Loading

0 comments on commit 30f26e4

Please sign in to comment.