lib/core: Inlined implementation of `abs`
[nit.git] / lib / c.nit
index deb6765..01f0bde 100644 (file)
--- a/lib/c.nit
+++ b/lib/c.nit
@@ -93,8 +93,8 @@ class CIntArray
                super size
        end
 
-       # Build from an `Array[Int]`
-       new from(array: Array[Int])
+       # Create from an `SequenceRead[Int]`
+       new from(array: SequenceRead[Int])
        do
                var carray = new CIntArray(array.length)
                for i in array.length.times do
@@ -129,7 +129,7 @@ class CByteArray
                super size
        end
 
-       # Build from a `SequenceRead[Byte]`
+       # Create from a `SequenceRead[Byte]`
        new from(array: SequenceRead[Byte])
        do
                var carray = new CByteArray(array.length)
@@ -138,6 +138,18 @@ class CByteArray
                end
                return carray
        end
+
+       # Safely move `n` bytes from `dst_offset` to `src_offset`, inside this array
+       #
+       # Require: all arguments greater than 0 and ranges within `length`
+       fun move(dst_offset, src_offset, n: Int)
+       do
+               assert dst_offset >= 0 and src_offset >= 0 and n >= 0
+               assert dst_offset + n <= length
+               assert src_offset + n <= length
+
+               native_array.move(dst_offset, src_offset, n)
+       end
 end
 
 # An array of `unsigned char` in C (`unsigned char*`)
@@ -152,6 +164,11 @@ extern class NativeCByteArray `{ unsigned char* `}
        redef fun []=(index, val) `{ self[index] = val; `}
 
        redef fun +(offset) `{ return self + offset; `}
+
+       # Move `n` bytes from `dst_offset` to `src_offset`
+       fun move(dst_offset, src_offset, n: Int) `{
+               memmove(self+dst_offset, self+src_offset, n);
+       `}
 end
 
 # Wrapper around an array of `NativeString` in C (`char**`) with length and destroy state.
@@ -166,8 +183,8 @@ class CNativeStringArray
                super size
        end
 
-       # Build from an `Array[NativeString]`
-       new from(array: Array[NativeString])
+       # Create from an `SequenceRead[NativeString]`
+       new from(array: SequenceRead[NativeString])
        do
                var carray = new CNativeStringArray(array.length)
                for i in array.length.times do