diff options
| author | Opportunity <[email protected]> | 2020-01-19 13:22:51 +0800 |
|---|---|---|
| committer | Opportunity <[email protected]> | 2020-01-19 13:22:51 +0800 |
| commit | 69ed0bdc01636c5ac093b6828c774285e3f72bbf (patch) | |
| tree | be2cb5cfdaa5af40371bac627a91bf03f59d0244 | |
| parent | f71f4eef3ff5d13b56a48dee05a0185125626ebd (diff) | |
table.move
| -rw-r--r-- | xmake/core/base/table.lua | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 328bd9f6c..04e258b95 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -25,6 +25,29 @@ local table = table or {} table.clear = require("table.clear") table.new = require("table.new") +-- move values of table(a1) to table(a2) +-- +-- disable the builtin implementation for android termux/arm64, it will crash when calling `table.move({1, 1}, 1, 2, 1, {})` +-- +-- @see https://github.com/xmake-io/xmake/pull/667#issuecomment-575859604 +-- +if xmake._ARCH:startswith("arm") then + function table.move(a1, f, e, t, a2) + if a2 == nil then a2 = a1 end + assert(a1) + assert(a2) + if e >= f then + local d = t - f + if t > e or t <= f or a2 ~= a1 then + for i = f, e do a2[i + d] = a1[i] end + else + for i = e, f, -1 do a2[i + d] = a1[i] end + end + end + return a2 + end +end + -- join all objects and tables function table.join(...) @@ -348,26 +371,5 @@ function table.reverse(arr) return revarr end --- move values of table(a1) to table(a2) --- --- disable the builtin implementation for android termux/arm64, it will crash when calling `table.move({1, 1}, 1, 2, 1, {})` --- --- @see https://github.com/xmake-io/xmake/pull/667#issuecomment-575859604 --- -if xmake._ARCH:startswith("arm") then - function table.move(a1, f, e, t, a2) - if a2 == nil then a2 = a1 end - if e >= f then - local d = t - f - if t > e or t <= f or a2 ~= a1 then - for i = f, e do a2[i + d] = a1[i] end - else - for i = e, f, -1 do a2[i + d] = a1[i] end - end - end - return a2 - end -end - -- return module: table return table |
