mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: tag array methods unsafe: *_many, grow_len, pointers (#8983)
This commit is contained in:
@@ -156,6 +156,7 @@ pub fn (mut a array) insert(i int, val voidptr) {
|
||||
}
|
||||
|
||||
// insert_many inserts many values into the array from index `i`.
|
||||
[unsafe]
|
||||
pub fn (mut a array) insert_many(i int, val voidptr, size int) {
|
||||
$if !no_bounds_checking ? {
|
||||
if i < 0 || i > a.len {
|
||||
@@ -178,8 +179,9 @@ pub fn (mut a array) prepend(val voidptr) {
|
||||
}
|
||||
|
||||
// prepend_many prepends another array to this array.
|
||||
[unsafe]
|
||||
pub fn (mut a array) prepend_many(val voidptr, size int) {
|
||||
a.insert_many(0, val, size)
|
||||
unsafe { a.insert_many(0, val, size) }
|
||||
}
|
||||
|
||||
// delete deletes array element at index `i`.
|
||||
@@ -420,7 +422,7 @@ fn (mut a array) push(val voidptr) {
|
||||
|
||||
// push_many implements the functionality for pushing another array.
|
||||
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
||||
// TODO make private, right now it's used by strings.Builder
|
||||
[unsafe]
|
||||
pub fn (mut a3 array) push_many(val voidptr, size int) {
|
||||
if a3.data == val && !isnil(a3.data) {
|
||||
// handle `arr << arr`
|
||||
@@ -632,6 +634,7 @@ pub fn (mut a array) grow_cap(amount int) {
|
||||
}
|
||||
|
||||
// grow_len ensures that an array has a.len + amount of length
|
||||
[unsafe]
|
||||
pub fn (mut a array) grow_len(amount int) {
|
||||
a.ensure_cap(a.len + amount)
|
||||
a.len += amount
|
||||
@@ -728,6 +731,7 @@ pub fn compare_f32(a &f32, b &f32) int {
|
||||
|
||||
// pointers returns a new array, where each element
|
||||
// is the address of the corresponding element in the array.
|
||||
[unsafe]
|
||||
pub fn (a array) pointers() []voidptr {
|
||||
mut res := []voidptr{}
|
||||
for i in 0 .. a.len {
|
||||
|
Reference in New Issue
Block a user