remove extra allocation from nu-json (#8299)

# Description

Remove unnecessary memory allocation

# User-Facing Changes

None

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.

Co-authored-by: None <>
This commit is contained in:
johnny-byte 2023-03-04 04:01:56 +03:00 committed by GitHub
parent 6148314dcd
commit bd096430cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -856,11 +856,7 @@ fn escape_char<W>(wr: &mut W, value: char) -> Result<()>
where
W: io::Write,
{
// FIXME: this allocation is required in order to be compatible with stable
// rust, which doesn't support encoding a `char` into a stack buffer.
let mut s = String::new();
s.push(value);
escape_bytes(wr, s.as_bytes())
escape_bytes(wr, value.encode_utf8(&mut [0; 4]).as_bytes())
}
fn fmt_f32_or_null<W>(wr: &mut W, value: f32) -> Result<()>