Make lexer buffer the whole file
This way, it won't have to go through a bunch of calls for each byte fetched.
This commit is contained in:
parent
cae703c0b1
commit
094d31f5e4
2 changed files with 82 additions and 67 deletions
|
|
@ -41,6 +41,7 @@ type reader =
|
|||
impure fn read_le_uint(uint size) -> uint;
|
||||
impure fn read_le_int(uint size) -> int;
|
||||
impure fn read_be_uint(uint size) -> uint;
|
||||
impure fn read_whole_stream() -> vec[u8];
|
||||
|
||||
impure fn seek(int offset, seek_style whence);
|
||||
impure fn tell() -> uint; // FIXME: eventually u64
|
||||
|
|
@ -170,6 +171,13 @@ state obj new_reader(buf_reader rdr) {
|
|||
}
|
||||
ret val;
|
||||
}
|
||||
impure fn read_whole_stream() -> vec[u8] {
|
||||
let vec[u8] buf = vec();
|
||||
while (!rdr.eof()) {
|
||||
buf += rdr.read(2048u);
|
||||
}
|
||||
ret buf;
|
||||
}
|
||||
impure fn seek(int offset, seek_style whence) {
|
||||
ret rdr.seek(offset, whence);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue