From 616ae95f6b4d3e427776e055ac6470010b4962a3 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 27 Apr 2011 18:18:09 -0700 Subject: stdlib: Use an unsafe cast to speed up the memory writer --- src/lib/io.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/io.rs b/src/lib/io.rs index 2c2c0dbf..4c1bf2df 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -450,7 +450,17 @@ type mutable_byte_buf = @rec(mutable vec[mutable u8] buf, mutable uint pos); state obj byte_buf_writer(mutable_byte_buf buf) { fn write(vec[u8] v) { - // FIXME: optimize + // Fast path. + if (buf.pos == _vec.len[mutable u8](buf.buf)) { + // FIXME: Fix our type system. There's no reason you shouldn't be + // able to add a mutable vector to an immutable one. + auto mv = _vec.rustrt.unsafe_vec_to_mut[u8](v); + buf.buf += mv; + buf.pos += _vec.len[u8](v); + ret; + } + + // FIXME: Optimize. These should be unique pointers. auto vlen = _vec.len[u8](v); auto vpos = 0u; while (vpos < vlen) { -- cgit v1.2.3