diff options
| author | ruki <[email protected]> | 2021-09-21 00:52:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-21 00:52:15 +0800 |
| commit | bce8f65cb9f619dfa30d7b4b1fa2da9fa56b58e1 (patch) | |
| tree | e05136ba9eaa706a2d2cabab6732a9410b05e297 /xmake/core/base/bytes.lua | |
| parent | 4181bf780192cbf4be257fb7b658cfb390684a12 (diff) | |
improve bytes
Diffstat (limited to 'xmake/core/base/bytes.lua')
| -rw-r--r-- | xmake/core/base/bytes.lua | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua index 300d2a073..9f7b6ca4f 100644 --- a/xmake/core/base/bytes.lua +++ b/xmake/core/base/bytes.lua @@ -96,7 +96,7 @@ function _instance.new(...) os.raise("incorrect bounds(%d-%d) for bytes(...)!", start, last) end instance._SIZE = last - start + 1 - instance._CDATA = libc.diffptr(b:cdata(), -1 + start) + instance._CDATA = b:cdata() -1 + start instance._REF = b -- keep lua ref for GC instance._MANAGED = false instance._READONLY = b:readonly() @@ -109,7 +109,7 @@ function _instance.new(...) instance._CDATA = libc.malloc(instance._SIZE, {gc = true}) local offset = 0 for _, b in ipairs(args) do - libc.memcpy(libc.diffptr(instance._CDATA, offset), b:cdata(), b:size()) + libc.memcpy(instance._CDATA + offset, b:cdata(), b:size()) offset = offset + b:size() end instance._MANAGED = true @@ -124,7 +124,7 @@ function _instance.new(...) instance._CDATA = libc.malloc(instance._SIZE, {gc = true}) local offset = 0 for _, b in ipairs(args) do - libc.memcpy(libc.diffptr(instance._CDATA, offset), b._CDATA, b:size()) + libc.memcpy(instance._CDATA + offset, b._CDATA, b:size()) offset = offset + b:size() end instance._MANAGED = true @@ -138,7 +138,7 @@ function _instance.new(...) os.raise("incorrect bounds(%d-%d)!", start, last) end instance._SIZE = last - start + 1 - instance._CDATA = libc.diffptr(b:cdata(), -1 + start) + instance._CDATA = b:cdata() -1 + start instance._REF = b -- keep lua ref for GC instance._MANAGED = false instance._READONLY = b:readonly() @@ -324,7 +324,7 @@ end -- convert bytes to string function _instance:str(i, j) local offset = i and i - 1 or 0 - return libc.strndup(libc.diffptr(self:cdata(), offset), (j or self:size()) - offset) + return libc.strndup(self:cdata() + offset, (j or self:size()) - offset) end -- get uint8 value |
