Skip to content

Commit

Permalink
improve linewidth
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Oct 25, 2024
1 parent 82c5c02 commit 9ab3585
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion xmake/core/base/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion xmake/modules/private/utils/bin2c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9ab3585

Please sign in to comment.