summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-07-10 23:11:47 +0800
committerruki <[email protected]>2019-07-10 13:10:46 +0800
commitac11149472ddf3da6918c7deec62059c7cec25e7 (patch)
treed37dec4a7821f51c22c1b4e3f909bf946b31a5eb
parente75bf9ac31aa544fd44a3e9da3bdcb4fd3d86004 (diff)
optimize to load lua file
-rw-r--r--core/src/xmake/io/file_close___gc.c2
-rw-r--r--core/src/xmake/io/file_flush.c2
-rw-r--r--xmake/core/_xmake_main.lua15
3 files changed, 13 insertions, 6 deletions
diff --git a/core/src/xmake/io/file_close___gc.c b/core/src/xmake/io/file_close___gc.c
index ebf74a63a..3ff136f6a 100644
--- a/core/src/xmake/io/file_close___gc.c
+++ b/core/src/xmake/io/file_close___gc.c
@@ -55,6 +55,7 @@ static tb_int_t xm_io_file_close_impl(lua_State* lua, tb_bool_t allow_closed_fil
// check
tb_assert(file->file_ref);
+#ifdef TB_CONFIG_OS_WINDOWS
// write cached data first
tb_byte_t const* odata = tb_buffer_data(&file->wcache);
tb_size_t osize = tb_buffer_size(&file->wcache);
@@ -63,6 +64,7 @@ static tb_int_t xm_io_file_close_impl(lua_State* lua, tb_bool_t allow_closed_fil
if (!tb_stream_bwrit(file->file_ref, odata, osize)) return tb_false;
tb_buffer_clear(&file->wcache);
}
+#endif
// close file
if (!tb_stream_clos(file->file_ref))
diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c
index 8be57d5fc..ccab16310 100644
--- a/core/src/xmake/io/file_flush.c
+++ b/core/src/xmake/io/file_flush.c
@@ -45,6 +45,7 @@ static tb_bool_t xm_io_file_flush_impl(xm_io_file* file)
// check
tb_assert_and_check_return_val(xm_io_file_is_file(file) && !xm_io_file_is_closed(file), tb_false);
+#ifdef TB_CONFIG_OS_WINDOWS
// write cached data first
tb_byte_t const* odata = tb_buffer_data(&file->wcache);
tb_size_t osize = tb_buffer_size(&file->wcache);
@@ -53,6 +54,7 @@ static tb_bool_t xm_io_file_flush_impl(xm_io_file* file)
if (!tb_stream_bwrit(file->file_ref, odata, osize)) return tb_false;
tb_buffer_clear(&file->wcache);
}
+#endif
return tb_stream_sync(file->file_ref, tb_false);
}
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index e0f5ab6f9..5e0a3a160 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -48,22 +48,25 @@ function loadfile(filepath)
end
end
- -- load script data from file
- local data, rerrors = io.readfile(filepath, {encoding = "binary"})
- if not data then
- return nil, rerrors
- end
-
-- init displaypath
+ local readopt = {}
local displaypath = filepath
if filepath:startswith(xmake._WORKING_DIR) then
displaypath = path.join(".", path.relative(filepath, xmake._WORKING_DIR))
elseif filepath:startswith(xmake._PROGRAM_DIR) then
+ readopt.encoding = "binary" -- read file by binary mode, will be faster
displaypath = path.join("$(programdir)", path.relative(filepath, xmake._PROGRAM_DIR))
elseif filepath:startswith(xmake._PROJECT_DIR) then
+ --readopt.encoding = "binary" -- read file by binary mode, will be faster
displaypath = path.join("$(projectdir)", path.relative(filepath, xmake._PROJECT_DIR))
end
+ -- load script data from file
+ local data, rerrors = io.readfile(filepath, readopt)
+ if not data then
+ return nil, rerrors
+ end
+
-- load script from string
local script, errors = load(data, "@" .. displaypath)
if script then