Remove vec version of str::bytes, rename bytes_ivec to str::bytes
This commit is contained in:
parent
d6626143cc
commit
2e7e58812b
16 changed files with 46 additions and 68 deletions
|
@ -98,7 +98,7 @@ fn item_type(item: &ebmlivec::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
|||
fn parse_external_def_id(this_cnum: ast::crate_num,
|
||||
extres: &external_resolver, s: str) ->
|
||||
ast::def_id {
|
||||
let buf = str::bytes_ivec(s);
|
||||
let buf = str::bytes(s);
|
||||
let external_def_id = parse_def_id(buf);
|
||||
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@ type encode_ctxt = {ccx: @crate_ctxt, type_abbrevs: abbrev_map};
|
|||
// Path table encoding
|
||||
fn encode_name(ebml_w: &ebmlivec::writer, name: &str) {
|
||||
ebmlivec::start_tag(ebml_w, tag_paths_data_name);
|
||||
ebml_w.writer.write(str::bytes_ivec(name));
|
||||
ebml_w.writer.write(str::bytes(name));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_def_id(ebml_w: &ebmlivec::writer, id: &def_id) {
|
||||
ebmlivec::start_tag(ebml_w, tag_def_id);
|
||||
ebml_w.writer.write(str::bytes_ivec(def_to_str(id)));
|
||||
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ fn encode_type_param_kinds(ebml_w: &ebmlivec::writer, tps: &[ty_param]) {
|
|||
|
||||
fn encode_variant_id(ebml_w: &ebmlivec::writer, vid: &def_id) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_variant);
|
||||
ebml_w.writer.write(str::bytes_ivec(def_to_str(vid)));
|
||||
ebml_w.writer.write(str::bytes(def_to_str(vid)));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
|
@ -207,20 +207,20 @@ fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer, typ: &ty::t) {
|
|||
|
||||
fn encode_symbol(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer, id: node_id) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::bytes_ivec(ecx.ccx.item_symbols.get(id)));
|
||||
ebml_w.writer.write(str::bytes(ecx.ccx.item_symbols.get(id)));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_discriminant(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
|
||||
id: node_id) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::bytes_ivec(ecx.ccx.discrim_symbols.get(id)));
|
||||
ebml_w.writer.write(str::bytes(ecx.ccx.discrim_symbols.get(id)));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_tag_id(ebml_w: &ebmlivec::writer, id: &def_id) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_tag_id);
|
||||
ebml_w.writer.write(str::bytes_ivec(def_to_str(id)));
|
||||
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ fn encode_meta_item(ebml_w: &ebmlivec::writer, mi: &meta_item) {
|
|||
meta_word(name) {
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_word);
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
|
||||
ebml_w.writer.write(str::bytes_ivec(name));
|
||||
ebml_w.writer.write(str::bytes(name));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
@ -452,10 +452,10 @@ fn encode_meta_item(ebml_w: &ebmlivec::writer, mi: &meta_item) {
|
|||
lit_str(value, _) {
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_name_value);
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
|
||||
ebml_w.writer.write(str::bytes_ivec(name));
|
||||
ebml_w.writer.write(str::bytes(name));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_value);
|
||||
ebml_w.writer.write(str::bytes_ivec(value));
|
||||
ebml_w.writer.write(str::bytes(value));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ fn encode_meta_item(ebml_w: &ebmlivec::writer, mi: &meta_item) {
|
|||
meta_list(name, items) {
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_list);
|
||||
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
|
||||
ebml_w.writer.write(str::bytes_ivec(name));
|
||||
ebml_w.writer.write(str::bytes(name));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
for inner_item: @meta_item in items {
|
||||
encode_meta_item(ebml_w, *inner_item);
|
||||
|
@ -575,7 +575,7 @@ fn encode_crate_deps(ebml_w: &ebmlivec::writer, cstore: &cstore::cstore) {
|
|||
ebmlivec::start_tag(ebml_w, tag_crate_deps);
|
||||
for cname: str in get_ordered_names(cstore) {
|
||||
ebmlivec::start_tag(ebml_w, tag_crate_dep);
|
||||
ebml_w.writer.write(str::bytes_ivec(cname));
|
||||
ebml_w.writer.write(str::bytes(cname));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
@ -610,7 +610,7 @@ fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
|
|||
encode_index(ebml_w, items_buckets, write_int);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
// Pad this, since something (LLVM, presumably) is cutting off the
|
||||
// remaining % 4 bytes_ivec.
|
||||
// remaining % 4 bytes.
|
||||
|
||||
buf_w.write(~[0u8, 0u8, 0u8, 0u8]);
|
||||
ret string_w.get_str();
|
||||
|
|
|
@ -340,18 +340,22 @@ fn uint_to_be_bytes(n: uint, size: uint) -> vec[u8] {
|
|||
|
||||
obj new_writer(out: buf_writer) {
|
||||
fn get_buf_writer() -> buf_writer { ret out; }
|
||||
fn write_str(s: str) { out.write(str::bytes(s)); }
|
||||
fn write_str(s: str) { out.write(ivec::to_vec(str::bytes(s))); }
|
||||
fn write_line(s: str) {
|
||||
out.write(str::bytes(s));
|
||||
out.write(str::bytes("\n"));
|
||||
out.write(ivec::to_vec(str::bytes(s)));
|
||||
out.write(ivec::to_vec(str::bytes("\n")));
|
||||
}
|
||||
fn write_char(ch: char) {
|
||||
// FIXME needlessly consy
|
||||
|
||||
out.write(str::bytes(str::from_char(ch)));
|
||||
out.write(ivec::to_vec(str::bytes(str::from_char(ch))));
|
||||
}
|
||||
fn write_int(n: int) {
|
||||
out.write(ivec::to_vec(str::bytes(int::to_str(n, 10u))));
|
||||
}
|
||||
fn write_uint(n: uint) {
|
||||
out.write(ivec::to_vec(str::bytes(uint::to_str(n, 10u))));
|
||||
}
|
||||
fn write_int(n: int) { out.write(str::bytes(int::to_str(n, 10u))); }
|
||||
fn write_uint(n: uint) { out.write(str::bytes(uint::to_str(n, 10u))); }
|
||||
fn write_bytes(bytes: vec[u8]) { out.write(bytes); }
|
||||
fn write_le_uint(n: uint, size: uint) {
|
||||
out.write(uint_to_le_bytes(n, size));
|
||||
|
|
|
@ -224,7 +224,7 @@ fn new_byte_buf_reader(buf: &[u8]) -> buf_reader {
|
|||
}
|
||||
|
||||
fn string_reader(s: &str) -> reader {
|
||||
ret new_reader(new_byte_buf_reader(str::bytes_ivec(s)));
|
||||
ret new_reader(new_byte_buf_reader(str::bytes(s)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -343,19 +343,19 @@ fn uint_to_be_bytes(n: uint, size: uint) -> [u8] {
|
|||
|
||||
obj new_writer(out: buf_writer) {
|
||||
fn get_buf_writer() -> buf_writer { ret out; }
|
||||
fn write_str(s: str) { out.write(str::bytes_ivec(s)); }
|
||||
fn write_str(s: str) { out.write(str::bytes(s)); }
|
||||
fn write_line(s: str) {
|
||||
out.write(str::bytes_ivec(s));
|
||||
out.write(str::bytes_ivec("\n"));
|
||||
out.write(str::bytes(s));
|
||||
out.write(str::bytes("\n"));
|
||||
}
|
||||
fn write_char(ch: char) {
|
||||
// FIXME needlessly consy
|
||||
|
||||
out.write(str::bytes_ivec(str::from_char(ch)));
|
||||
out.write(str::bytes(str::from_char(ch)));
|
||||
}
|
||||
fn write_int(n: int) { out.write(str::bytes_ivec(int::to_str(n, 10u))); }
|
||||
fn write_int(n: int) { out.write(str::bytes(int::to_str(n, 10u))); }
|
||||
fn write_uint(n: uint) {
|
||||
out.write(str::bytes_ivec(uint::to_str(n, 10u)));
|
||||
out.write(str::bytes(uint::to_str(n, 10u)));
|
||||
}
|
||||
fn write_bytes(bytes: &[u8]) { out.write(bytes); }
|
||||
fn write_le_uint(n: uint, size: uint) {
|
||||
|
|
|
@ -245,7 +245,7 @@ fn mk_sha1() -> sha1 {
|
|||
add_input(st, m);
|
||||
}
|
||||
fn input_ivec(msg: &[u8]) { add_input(st, msg); }
|
||||
fn input_str(msg: &str) { add_input(st, str::bytes_ivec(msg)); }
|
||||
fn input_str(msg: &str) { add_input(st, str::bytes(msg)); }
|
||||
fn result() -> vec[u8] {
|
||||
let rivec = mk_result(st);
|
||||
let rvec = [];
|
||||
|
|
|
@ -49,7 +49,6 @@ export connect;
|
|||
export connect_ivec;
|
||||
export to_upper;
|
||||
export safe_slice;
|
||||
export bytes_ivec;
|
||||
export unsafe_from_bytes_ivec;
|
||||
export is_empty;
|
||||
export is_not_empty;
|
||||
|
@ -63,7 +62,6 @@ export trim;
|
|||
native "rust" mod rustrt {
|
||||
type sbuf;
|
||||
fn str_buf(s: str) -> sbuf;
|
||||
fn str_vec(s: str) -> vec[u8];
|
||||
fn str_byte_len(s: str) -> uint;
|
||||
fn str_alloc(n_bytes: uint) -> str;
|
||||
fn str_from_ivec(b: &[mutable? u8]) -> str;
|
||||
|
@ -189,9 +187,7 @@ fn byte_len(s: str) -> uint { ret rustrt::str_byte_len(s); }
|
|||
|
||||
fn buf(s: &str) -> sbuf { ret rustrt::str_buf(s); }
|
||||
|
||||
fn bytes(s: &str) -> vec[u8] { ret rustrt::str_vec(s); }
|
||||
|
||||
fn bytes_ivec(s: str) -> [u8] {
|
||||
fn bytes(s: str) -> [u8] {
|
||||
let sbuffer = buf(s);
|
||||
let ptr = unsafe::reinterpret_cast(sbuffer);
|
||||
ret ivec::unsafe::from_buf(ptr, byte_len(s));
|
||||
|
|
|
@ -277,32 +277,6 @@ str_buf(rust_task *task, rust_str *s)
|
|||
return (char const *)&s->data[0];
|
||||
}
|
||||
|
||||
extern "C" CDECL rust_vec*
|
||||
str_vec(rust_task *task, rust_str *s)
|
||||
{
|
||||
// FIXME: this should just upref s and return it, but we
|
||||
// accidentally made too much of the language and runtime know
|
||||
// and care about the difference between str and vec (trailing null);
|
||||
// eliminate these differences and then rewrite this back to just
|
||||
// the following:
|
||||
//
|
||||
// if (s->ref_count != CONST_REFCOUNT)
|
||||
// s->ref();
|
||||
// return s;
|
||||
|
||||
rust_str *v =
|
||||
vec_alloc_with_data(task,
|
||||
s->fill - 1,
|
||||
s->fill - 1,
|
||||
1,
|
||||
(s->fill - 1) ? (void*)s->data : NULL);
|
||||
if (!v) {
|
||||
task->fail();
|
||||
return NULL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
extern "C" CDECL size_t
|
||||
str_byte_len(rust_task *task, rust_str *s)
|
||||
{
|
||||
|
|
|
@ -68,7 +68,6 @@ str_from_ivec
|
|||
str_from_vec
|
||||
str_push_byte
|
||||
str_slice
|
||||
str_vec
|
||||
take_chan
|
||||
task_sleep
|
||||
task_yield
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
use std;
|
||||
|
||||
import std::vec;
|
||||
import std::ivec;
|
||||
import std::uint;
|
||||
import std::time;
|
||||
import std::str;
|
||||
|
@ -88,7 +89,8 @@ fn main(argv: vec[str]) {
|
|||
if opts.stress {
|
||||
stress(2);
|
||||
} else {
|
||||
let max = uint::parse_buf(str::bytes(argv.(1)), 10u) as int;
|
||||
let max = uint::parse_buf(ivec::to_vec(str::bytes(argv.(1))),
|
||||
10u) as int;
|
||||
|
||||
let num_trials = 10;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std;
|
||||
import std::vec;
|
||||
import std::ivec;
|
||||
import std::task;
|
||||
import std::uint;
|
||||
import std::str;
|
||||
|
@ -19,7 +20,7 @@ fn main(args: vec[str]) {
|
|||
let n = if vec::len(args) < 2u {
|
||||
10u
|
||||
} else {
|
||||
uint::parse_buf(str::bytes(args.(1)), 10u)
|
||||
uint::parse_buf(ivec::to_vec(str::bytes(args.(1))), 10u)
|
||||
};
|
||||
let i = 0u;
|
||||
while i < n {
|
||||
|
|
|
@ -107,7 +107,7 @@ mod map_reduce {
|
|||
none. {
|
||||
// log_err "fetching new channel for " + key;
|
||||
let p = port[chan[reduce_proto]]();
|
||||
let keyi = str::bytes_ivec(key);
|
||||
let keyi = str::bytes(key);
|
||||
ctrl <| find_reducer(keyi, chan(p));
|
||||
p |> c;
|
||||
im.insert(key, clone(c));
|
||||
|
|
|
@ -81,7 +81,7 @@ fn test_in_fn_ctxt() {
|
|||
mod test_native_items {
|
||||
native "rust" mod rustrt {
|
||||
#[cfg(bogus)]
|
||||
fn str_vec(s: str) -> vec[u8];
|
||||
fn str_vec(s: str) -> vec[u8];
|
||||
fn str_byte_len(s: str) -> uint;
|
||||
fn str_byte_len(s: str) -> uint;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ fn main() {
|
|||
let srv: sio::server = sio::create_server(cx, "0.0.0.0", 9090);
|
||||
let child: task = spawn connectTask(cx, "127.0.0.1", 9090);
|
||||
let client: sio::client = sio::accept_from(srv);
|
||||
sio::write_data(client, str::bytes_ivec("hello, world\n"));
|
||||
sio::write_data(client, str::bytes("hello, world\n"));
|
||||
task::join(child);
|
||||
sio::close_client(client);
|
||||
sio::close_server(srv);
|
||||
|
|
|
@ -18,7 +18,7 @@ fn main() {
|
|||
let srv: sio::server = sio::create_server(cx, "0.0.0.0", 9090);
|
||||
let child: task = spawn connectTask(cx, "127.0.0.1", 9090);
|
||||
let client: sio::client = sio::accept_from(srv);
|
||||
sio::write_data(client, str::bytes_ivec("hello, world\n"));
|
||||
sio::write_data(client, str::bytes("hello, world\n"));
|
||||
task::join(child);
|
||||
sio::close_client(client);
|
||||
sio::close_server(srv);
|
||||
|
|
|
@ -2,6 +2,7 @@ use std;
|
|||
import std::str;
|
||||
import std::vec;
|
||||
import std::io;
|
||||
import std::ivec;
|
||||
|
||||
fn main() {
|
||||
// Chars of 1, 2, 3, and 4 bytes
|
||||
|
@ -15,7 +16,7 @@ fn main() {
|
|||
assert (str::char_at(s, 0u) == 'e');
|
||||
assert (str::char_at(s, 1u) == 'é');
|
||||
|
||||
assert (str::is_utf8(str::bytes(s)));
|
||||
assert (str::is_utf8(ivec::to_vec(str::bytes(s))));
|
||||
assert (!str::is_utf8([0x80_u8]));
|
||||
assert (!str::is_utf8([0xc0_u8]));
|
||||
assert (!str::is_utf8([0xc0_u8, 0x10_u8]));
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
use std;
|
||||
import std::str;
|
||||
import std::vec;
|
||||
import std::ivec;
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
|
@ -15,7 +16,7 @@ fn test_simple() {
|
|||
* working, but we should implement is_utf8 before that happens.
|
||||
*/
|
||||
|
||||
let v: vec[u8] = str::bytes(s1);
|
||||
let v: vec[u8] = ivec::to_vec(str::bytes(s1));
|
||||
let s2: str = str::from_bytes(v);
|
||||
let i: uint = 0u;
|
||||
let n1: uint = str::byte_len(s1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue