summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-18 22:25:42 +0800
committerruki <[email protected]>2025-10-18 22:25:42 +0800
commitc3c6731404b9e28915ac10b79c6cc6ad6ecc1996 (patch)
tree6386b81ac105f2da6160052958da071b529ab39e
parent435242713b1d1ed077c264228c0216dfa985685f (diff)
improve file read
-rw-r--r--core/src/xmake/io/file_read.c10
-rw-r--r--core/src/xmake/io/prefix.h2
2 files changed, 8 insertions, 4 deletions
diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c
index 2647a056b..ecbb04dbd 100644
--- a/core/src/xmake/io/file_read.c
+++ b/core/src/xmake/io/file_read.c
@@ -57,7 +57,7 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re
tb_hong_t size = tb_stream_size(stream);
while (size < 0 || (offset = tb_stream_offset(stream)) < size)
{
- tb_long_t real = tb_stream_peek(stream, &data, TB_STREAM_BLOCK_MAXN);
+ tb_long_t real = tb_stream_peek(stream, &data, XM_IO_BLOCK_MAXN);
if (real > 0)
{
tb_char_t const* e = tb_strnchr((tb_char_t const*)data, real, '\n');
@@ -184,12 +184,14 @@ static tb_int_t xm_io_file_read_all_directly(lua_State* lua, xm_io_file_t* file)
if (!tb_buffer_init(&buf))
xm_io_return_error(lua, "init buffer failed!");
+ tb_byte_t* data = tb_buffer_resize(&file->rcache, XM_IO_BLOCK_MAXN);
+ tb_assert(data);
+
// read all
- tb_byte_t data[TB_STREAM_BLOCK_MAXN];
- tb_stream_ref_t stream = file->u.file_ref;
+ tb_stream_ref_t stream = file->u.file_ref;
while (!tb_stream_beof(stream))
{
- tb_long_t real = tb_stream_read(stream, data, sizeof(data));
+ tb_long_t real = tb_stream_read(stream, data, XM_IO_BLOCK_MAXN);
if (real > 0)
tb_buffer_memncat(&buf, data, real);
else if (!real)
diff --git a/core/src/xmake/io/prefix.h b/core/src/xmake/io/prefix.h
index ec2cc7216..df4d09a17 100644
--- a/core/src/xmake/io/prefix.h
+++ b/core/src/xmake/io/prefix.h
@@ -29,6 +29,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
+#define XM_IO_BLOCK_MAXN (TB_STREAM_BLOCK_MAXN * 10)
+
#define xm_io_file_is_file(file) ((file)->type == XM_IO_FILE_TYPE_FILE)
#define xm_io_file_is_std(file) ((file)->type != XM_IO_FILE_TYPE_FILE)
#define xm_io_file_is_tty(file) (!!((file)->type & XM_IO_FILE_FLAG_TTY))