1
Fork 0

Eliminate a copy in syntax::parse::new_parser_from_file

Fixing a FIXME turned out to be pretty involved. I added an io function
that returns a unique boxed string (for the contents of a file) rather than
a string, and went from there. Also made the src field of codemap a unique
boxed string. This doesn't seem to make that much difference in amount of
allocation according to valgrind (disappointingly), but I also had to introduce
a copy somewhere else pending a new snapshot, so maybe that's it.
This commit is contained in:
Tim Chevalier 2012-04-27 14:21:17 -07:00
parent dc117fecde
commit 2bb3b63ec4
15 changed files with 88 additions and 43 deletions

View file

@ -123,6 +123,19 @@ fn from_bytes(vv: [u8]) -> str unsafe {
ret unsafe::from_bytes(vv);
}
#[doc = "
Convert a unique vector of bytes (passed by move)
to a unique boxed UTF-8 string
# Failure
Fails if invalid UTF-8
"]
fn from_bytes_move(-vv: ~mut [const u8]) -> ~str unsafe {
assert is_utf8(::unsafe::reinterpret_cast(vv));
ret unsafe::from_bytes_move(vv);
}
#[doc = "
Convert a byte to a UTF-8 string
@ -1631,6 +1644,7 @@ mod unsafe {
from_buf,
from_c_str,
from_bytes,
from_bytes_move,
slice_bytes,
push_byte,
pop_byte,
@ -1685,6 +1699,13 @@ mod unsafe {
ret scopy;
}
unsafe fn from_bytes_move(-v: ~mut [const u8]) -> ~str unsafe {
*v += [0u8];
let s: ~str = ::unsafe::reinterpret_cast(v);
::unsafe::forget(v);
s
}
#[doc = "
Converts a byte to a string.