summaryrefslogtreecommitdiff
path: root/xmake/core/base/bytes.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-11-02 00:38:59 +0800
committerruki <[email protected]>2019-11-01 21:53:55 +0800
commit6d4ad7fe1c5f8ac44b420a8cb5de0bc9cd0d37b6 (patch)
tree059cf0d49ec8d7ef2f13c0c415f79619663c034c /xmake/core/base/bytes.lua
parent2359364d3b4d8ff6c282be9ff721fc2d820d15a9 (diff)
improve bytes ctor
Diffstat (limited to 'xmake/core/base/bytes.lua')
-rw-r--r--xmake/core/base/bytes.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua
index 8b6fbee3c..377341480 100644
--- a/xmake/core/base/bytes.lua
+++ b/xmake/core/base/bytes.lua
@@ -104,6 +104,21 @@ function _instance.new(...)
end
instance._MANAGED = true
instance._READONLY = false
+ elseif not arg2 and arg1[1] and type(arg1[1]) == 'table' then
+ -- bytes({bytes1, bytes2, ...}) : allocates and concat buffer from a list of byte buffers (table)
+ args = arg1
+ instance._SIZE = 0
+ for _, b in ipairs(args) do
+ instance._SIZE = instance._SIZE + b:size()
+ end
+ instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ffi.C.xm_ffi_malloc(instance._SIZE)), ffi.C.xm_ffi_free)
+ local offset = 0
+ for _, b in ipairs(args) do
+ ffi.copy(instance._CDATA + offset, b._CDATA, b:size())
+ offset = offset + b:size()
+ end
+ instance._MANAGED = true
+ instance._READONLY = false
elseif not arg2 and arg1:size() then
-- bytes(bytes): allocates a buffer from another one (strict replica, sharing memory)
local b = arg1