diff options
| author | Brian Anderson <[email protected]> | 2011-03-06 13:42:50 -0500 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-06 15:13:28 -0800 |
| commit | 330c9c6c3592496462dbf9aa716a37e048b00172 (patch) | |
| tree | 97b2e94088ee5aa094da2e83d6ccda0aaa071f17 /src/lib | |
| parent | Fix return value on trans_vec_add. (diff) | |
| download | rust-330c9c6c3592496462dbf9aa716a37e048b00172.tar.xz rust-330c9c6c3592496462dbf9aa716a37e048b00172.zip | |
Make _str.bytes use _vec.init_fn. Remove FIXME.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/_str.rs | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/src/lib/_str.rs b/src/lib/_str.rs index 6b7ac018..0e0e7650 100644 --- a/src/lib/_str.rs +++ b/src/lib/_str.rs @@ -96,25 +96,10 @@ fn buf(str s) -> sbuf { } fn bytes(str s) -> vec[u8] { - /* FIXME (issue #58): - * Should be... - * - * fn ith(str s, uint i) -> u8 { - * ret s.(i); - * } - * ret _vec.init_fn[u8](bind ith(s, _), byte_len(s)); - * - * but we do not correctly decrement refcount of s when - * the binding dies, so we have to do this manually. - */ - let uint n = _str.byte_len(s); - let vec[u8] v = _vec.alloc[u8](n); - let uint i = 0u; - while (i < n) { - v += vec(s.(i)); - i += 1u; + fn ith(str s, uint i) -> u8 { + ret s.(i); } - ret v; + ret _vec.init_fn[u8](bind ith(s, _), byte_len(s)); } fn from_bytes(vec[u8] v) : is_utf8(v) -> str { |