diff options
| author | ruki <[email protected]> | 2019-07-06 12:32:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-07-06 12:32:00 +0800 |
| commit | efa0f9991fc2f3b394155f5de25ef66343156ab8 (patch) | |
| tree | 903f436b500f5988592af61fded801789a4e664e /core/src | |
| parent | 6d7a7e8fef7ca7d1129883e02c6dad2314b47259 (diff) | |
optimize to read all again
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/io/file_read.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 6d16748ff..3152c4733 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -54,10 +54,13 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re // read line and reserve crlf tb_char_t ch = 0; tb_bool_t eof = tb_false; - tb_size_t need = 512; tb_byte_t* p = tb_null; - while (!tb_stream_beof(stream)) + tb_hong_t size = tb_stream_size(stream); + tb_hize_t offset = 0; + while (size < 0 || (offset = tb_stream_offset(stream)) < size) { + tb_hize_t left = size >= offset? size - offset : -1; + tb_size_t need = (tb_size_t)tb_min(left, 512); if (need && tb_stream_need(stream, &p, need) && p) { tb_char_t const* e = tb_strnchr((tb_char_t const*)p, need, '\n'); @@ -95,9 +98,9 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re } // ok? - tb_size_t size = tb_buffer_size(line); - if (size) return size; - else return (tb_stream_beof(stream) || eof)? -1 : 0; + tb_size_t linesize = tb_buffer_size(line); + if (linesize) return linesize; + else return (eof || tb_stream_beof(stream))? -1 : 0; } static tb_int_t xm_io_file_buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char_t const* continuation, tb_bool_t keep_crlf) { |
