@@ -194,7 +194,8 @@ fn (mut a array) ensure_cap(required int) {
194
194
return
195
195
}
196
196
if a.flags.has (.nogrow) {
197
- panic ('array.ensure_cap: array with the flag `.nogrow` cannot grow in size, array required new size: ${required} ' )
197
+ panic_n ('array.ensure_cap: array with the flag `.nogrow` cannot grow in size, array required new size:' ,
198
+ required)
198
199
}
199
200
mut cap := if a.cap > 0 { i64 (a.cap) } else { i64 (2 ) }
200
201
for required > cap {
@@ -205,7 +206,8 @@ fn (mut a array) ensure_cap(required int) {
205
206
// limit the capacity, since bigger values, will overflow the 32bit integer used to store it
206
207
cap = max_int
207
208
} else {
208
- panic ('array.ensure_cap: array needs to grow to cap = ${cap} , which is > 2^31' )
209
+ panic_n ('array.ensure_cap: array needs to grow to cap (which is > 2^31):' ,
210
+ cap)
209
211
}
210
212
}
211
213
new_size := u64 (cap) * u64 (a.element_size)
@@ -240,7 +242,7 @@ pub fn (a array) repeat(count int) array {
240
242
@[direct_array_access; unsafe ]
241
243
pub fn (a array) repeat_to_depth (count int , depth int ) array {
242
244
if count < 0 {
243
- panic ('array.repeat: count is negative: ${ count} ' )
245
+ panic_n ('array.repeat: count is negative:' , count)
244
246
}
245
247
mut size := u64 (count) * u64 (a.len) * u64 (a.element_size)
246
248
if size == 0 {
@@ -293,7 +295,7 @@ pub fn (a array) repeat_to_depth(count int, depth int) array {
293
295
// ```
294
296
pub fn (mut a array) insert (i int , val voidptr ) {
295
297
if i < 0 || i > a.len {
296
- panic ('array.insert: index out of range (i == ${i} , a.len == ${ a.len} )' )
298
+ panic_n2 ('array.insert: index out of range (i, a.len):' , i, a.len)
297
299
}
298
300
if a.len == max_int {
299
301
panic ('array.insert: a.len reached max_int' )
@@ -313,11 +315,11 @@ pub fn (mut a array) insert(i int, val voidptr) {
313
315
@[unsafe ]
314
316
fn (mut a array) insert_many (i int , val voidptr , size int ) {
315
317
if i < 0 || i > a.len {
316
- panic ('array.insert_many: index out of range (i == ${i} , a.len == ${ a.len} )' )
318
+ panic_n2 ('array.insert_many: index out of range (i, a.len):' , i, a.len)
317
319
}
318
320
new_len := i64 (a.len) + i64 (size)
319
321
if new_len > max_int {
320
- panic ('array.insert_many: a.len = ${new_len} will exceed max_int' )
322
+ panic_n ('array.insert_many: max_int will be exceeded by a.len:' , new_len )
321
323
}
322
324
a.ensure_cap (int (new_len))
323
325
elem_size := a.element_size
@@ -374,8 +376,12 @@ pub fn (mut a array) delete(i int) {
374
376
// ```
375
377
pub fn (mut a array) delete_many (i int , size int ) {
376
378
if i < 0 || i64 (i) + i64 (size) > i64 (a.len) {
377
- endidx := if size > 1 { '..${i + size} ' } else { '' }
378
- panic ('array.delete: index out of range (i == ${i}${endidx} , a.len == ${a.len} )' )
379
+ if size > 1 {
380
+ panic_n3 ('array.delete: index out of range (i,i+size,a.len):' , i, i + size,
381
+ a.len)
382
+ } else {
383
+ panic_n2 ('array.delete: index out of range (i,a.len):' , i, a.len)
384
+ }
379
385
}
380
386
if a.flags.all (.noshrink | .noslices) {
381
387
unsafe {
@@ -465,7 +471,7 @@ fn (a array) get_unsafe(i int) voidptr {
465
471
fn (a array) get (i int ) voidptr {
466
472
$if ! no_bounds_checking {
467
473
if i < 0 || i > = a.len {
468
- panic ('array.get: index out of range (i == ${i} , a.len == ${ a.len} )' )
474
+ panic_n2 ('array.get: index out of range (i, a.len):' , i, a.len)
469
475
}
470
476
}
471
477
unsafe {
@@ -557,13 +563,15 @@ fn (a array) slice(start int, _end int) array {
557
563
end := if _end == max_int { a.len } else { _end } // max_int
558
564
$if ! no_bounds_checking {
559
565
if start > end {
560
- panic ('array.slice: invalid slice index (${start} > ${end} )' )
566
+ panic ('array.slice: invalid slice index (start>end):' + i64 (start).str () + ', ' +
567
+ i64 (end).str ())
561
568
}
562
569
if end > a.len {
563
- panic ('array.slice: slice bounds out of range (${end} >= ${a.len} )' )
570
+ panic ('array.slice: slice bounds out of range (' + i64 (end).str () + ' >= ' +
571
+ i64 (a.len).str () + ')' )
564
572
}
565
573
if start < 0 {
566
- panic ('array.slice: slice bounds out of range (${ start} < 0)' )
574
+ panic ('array.slice: slice bounds out of range (start<0):' + start. str () )
567
575
}
568
576
}
569
577
// TODO: integrate reference counting
@@ -683,7 +691,7 @@ fn (mut a array) set_unsafe(i int, val voidptr) {
683
691
fn (mut a array) set (i int , val voidptr ) {
684
692
$if ! no_bounds_checking {
685
693
if i < 0 || i > = a.len {
686
- panic ('array.set: index out of range (i == ${i} , a.len == ${ a.len} )' )
694
+ panic_n2 ('array.set: index out of range (i, a.len):' , i, a.len)
687
695
}
688
696
}
689
697
unsafe { vmemcpy (& u8 (a.data) + u64 (a.element_size) * u64 (i), val, a.element_size) }
@@ -1000,7 +1008,7 @@ pub fn copy(mut dst []u8, src []u8) int {
1000
1008
pub fn (mut a array) grow_cap (amount int ) {
1001
1009
new_cap := i64 (amount) + i64 (a.cap)
1002
1010
if new_cap > max_int {
1003
- panic ('array.grow_cap: new capacity ${new_cap} will exceed max_int' )
1011
+ panic_n ('array.grow_cap: max_int will be exceeded by new cap:' , new_cap )
1004
1012
}
1005
1013
a.ensure_cap (int (new_cap))
1006
1014
}
@@ -1013,7 +1021,7 @@ pub fn (mut a array) grow_cap(amount int) {
1013
1021
pub fn (mut a array) grow_len (amount int ) {
1014
1022
new_len := i64 (amount) + i64 (a.len)
1015
1023
if new_len > max_int {
1016
- panic ('array.grow_len: new len ${new_len} will exceed max_int' )
1024
+ panic_n ('array.grow_len: max_int will be exceeded by new len:' , new_len )
1017
1025
}
1018
1026
a.ensure_cap (int (new_len))
1019
1027
a.len = int (new_len)
@@ -1053,13 +1061,13 @@ pub fn (data &u8) vbytes(len int) []u8 {
1053
1061
@[if ! no_bounds_checking ? ; inline]
1054
1062
fn panic_on_negative_len (len int ) {
1055
1063
if len < 0 {
1056
- panic ('negative .len' )
1064
+ panic_n ('negative .len:' , len )
1057
1065
}
1058
1066
}
1059
1067
1060
1068
@[if ! no_bounds_checking ? ; inline]
1061
1069
fn panic_on_negative_cap (cap int ) {
1062
1070
if cap < 0 {
1063
- panic ('negative .cap' )
1071
+ panic_n ('negative .cap:' , cap )
1064
1072
}
1065
1073
}
0 commit comments