summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-10-25 22:53:02 +0800
committerruki <[email protected]>2024-10-25 22:53:02 +0800
commit9ab3585df20a4b59e75675d86eb488154c0449e9 (patch)
treee1fbe36e6d50d451ec71237cfa2f2069fd7dde28
parent82c5c02fdf20a93ef3073f475b6c449dd7cba24b (diff)
improve linewidth
-rw-r--r--xmake/core/base/utils.lua2
-rw-r--r--xmake/modules/private/utils/bin2c.lua18
2 files changed, 18 insertions, 2 deletions
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 8f1f9a3d0..99add99bc 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -324,7 +324,7 @@ end
-- generate c/c++ code from the binary file
function utils.bin2c(binaryfile, outputfile, opt)
opt = opt or {}
- return utils._bin2c(binaryfile, outputfile, opt.linewidth or 0x20, opt.nozeroend or false)
+ return utils._bin2c(binaryfile, outputfile, opt.linewidth or 32, opt.nozeroend or false)
end
-- return module
diff --git a/xmake/modules/private/utils/bin2c.lua b/xmake/modules/private/utils/bin2c.lua
index 987a478f7..29c89338e 100644
--- a/xmake/modules/private/utils/bin2c.lua
+++ b/xmake/modules/private/utils/bin2c.lua
@@ -35,7 +35,7 @@ function _do_dump(binarydata, outputfile, opt)
local p = 0
local e = binarydata:size()
local line = nil
- local linewidth = opt.linewidth or 0x20
+ local linewidth = opt.linewidth or 32
local first = true
while p < e do
line = ""
@@ -81,6 +81,22 @@ function _do_bin2c(binarypath, outputpath, opt)
-- trace
print("generating code data file from %s ..", binarypath)
+ -- optimize the default linewidth for reading large file
+ if not opt.linewidth then
+ local filesize = os.filesize(binarypath)
+ if filesize > 1024 * 1024 * 1024 then
+ opt.linewidth = 512
+ elseif filesize > 100 * 1024 * 1024 then
+ opt.linewidth = 256
+ elseif filesize > 10 * 1024 * 1024 then
+ opt.linewidth = 128
+ elseif filesize > 1024 * 1024 then
+ opt.linewidth = 64
+ else
+ opt.linewidth = 32
+ end
+ end
+
-- do dump
if utils.bin2c then
utils.bin2c(binarypath, outputpath, opt)