Skip to content

Commit bb0470e

Browse files
committed
sema: use slices::Grow instead of custom implementation
1 parent 7ff3141 commit bb0470e

1 file changed

Lines changed: 2 additions & 16 deletions

File tree

std/jule/sema/scope.jule

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use "std/jule/constant"
1010
use "std/jule/log"
1111
use "std/jule/token"
1212
use "std/jule/types"
13+
use "std/slices"
1314
use "std/strings"
1415

1516
// Statement type.
@@ -2442,7 +2443,7 @@ impl scopeChecker {
24422443
// Following append calls will append the group members
24432444
// to slice's selected memory block.
24442445
tn := len(self.table.Vars)
2445-
self.table.Vars = growSlice(self.table.Vars, len(astv.Group))
2446+
self.table.Vars = slices::Grow(self.table.Vars, len(astv.Group))
24462447
mut group := self.table.Vars[tn : tn+len(astv.Group) : tn+len(astv.Group)]
24472448
for (i, mut v) in astv.Group {
24482449
mut cv := buildVar(v)
@@ -2904,19 +2905,4 @@ fn isValidStmtForNext2(st: Stmt): bool {
29042905
|:
29052906
ret false
29062907
}
2907-
}
2908-
2909-
// Increases the slice's capacity, if necessary, to guarantee space for
2910-
// another n elements. After growSlice(n), at least n elements can be appended
2911-
// to the slice without another allocation. If n is negative or too large to
2912-
// allocate the memory, it panics.
2913-
fn growSlice[S: []E, E](mut s: S, mut n: int): S {
2914-
if n < 0 {
2915-
panic("cannot be negative")
2916-
}
2917-
n -= cap(s) - len(s)
2918-
if n > 0 {
2919-
s = append(s[:cap(s)], make([]E, n)...)[:len(s)]
2920-
}
2921-
ret s
29222908
}

0 commit comments

Comments
 (0)