diff options
| author | Patrick Walton <[email protected]> | 2011-04-27 18:18:09 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-04-27 18:18:28 -0700 |
| commit | 616ae95f6b4d3e427776e055ac6470010b4962a3 (patch) | |
| tree | 54e8cb68e5f2ab5add7a1a7603af8177f12e2188 /src/lib | |
| parent | stdlib/rt: Add an unsafe function to cast immutable vectors to mutable ones (diff) | |
| download | rust-616ae95f6b4d3e427776e055ac6470010b4962a3.tar.xz rust-616ae95f6b4d3e427776e055ac6470010b4962a3.zip | |
stdlib: Use an unsafe cast to speed up the memory writer
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/io.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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) { |