diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-03-11 11:01:46 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-03-22 10:25:30 -0700 |
| commit | 48d5fe9ec560b53b1f5069219b0d62015e1de5ba (patch) | |
| tree | 94f12e261a6d8513968aee2ad8cbb965fdecdf86 /src/libserialize | |
| parent | c7bdfd4442f0bde3412f08336f75b9eabff4a938 (diff) | |
| download | rust-48d5fe9ec560b53b1f5069219b0d62015e1de5ba.tar.gz rust-48d5fe9ec560b53b1f5069219b0d62015e1de5ba.zip | |
std: Change `encode_utf{8,16}` to return iterators
Currently these have non-traditional APIs which take a buffer and report how much was filled in, but they're not necessarily ergonomic to use. Returning an iterator which *also* exposes an underlying slice shouldn't result in any performance loss as it's just a lazy version of the same implementation, and it's also much more ergonomic! cc #27784
Diffstat (limited to 'src/libserialize')
| -rw-r--r-- | src/libserialize/json.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index b95eddbc661..ab16ef23dd1 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -433,10 +433,9 @@ fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult { } fn escape_char(writer: &mut fmt::Write, v: char) -> EncodeResult { - let mut buf = [0; 4]; - let n = v.encode_utf8(&mut buf).unwrap(); - let buf = unsafe { str::from_utf8_unchecked(&buf[..n]) }; - escape_str(writer, buf) + escape_str(writer, unsafe { + str::from_utf8_unchecked(v.encode_utf8().as_slice()) + }) } fn spaces(wr: &mut fmt::Write, mut n: usize) -> EncodeResult { |
