@@ -8,7 +8,7 @@ const bun = @import("root").bun;
8
8
pub fn BabyList (comptime Type : type ) type {
9
9
return struct {
10
10
const ListType = @This ();
11
- ptr : [* ]Type = undefined ,
11
+ ptr : ? [* ]Type = null ,
12
12
len : u32 = 0 ,
13
13
cap : u32 = 0 ,
14
14
@@ -21,7 +21,7 @@ pub fn BabyList(comptime Type: type) type {
21
21
}
22
22
23
23
pub fn available (this : * @This ()) []Type {
24
- return this .ptr [this .len .. this .cap ];
24
+ return this .ptr .? [this .len .. this .cap ];
25
25
}
26
26
27
27
pub fn deinitWithAllocator (this : * @This (), allocator : std .mem .Allocator ) void {
@@ -30,7 +30,7 @@ pub fn BabyList(comptime Type: type) type {
30
30
}
31
31
32
32
pub fn contains (this : @This (), item : []const Type ) bool {
33
- return this .len > 0 and @intFromPtr (item .ptr ) >= @intFromPtr (this .ptr ) and @intFromPtr (item .ptr ) < @intFromPtr (this .ptr ) + this .len ;
33
+ return this .len > 0 and @intFromPtr (item .ptr ) >= @intFromPtr (this .ptr .? ) and @intFromPtr (item .ptr ) < @intFromPtr (this .ptr .? ) + this .len ;
34
34
}
35
35
36
36
pub inline fn initConst (items : []const Type ) ListType {
@@ -52,7 +52,7 @@ pub fn BabyList(comptime Type: type) type {
52
52
pub fn popOrNull (this : * @This ()) ? Type {
53
53
if (this .len == 0 ) return null ;
54
54
this .len -= 1 ;
55
- return this .ptr [this .len ];
55
+ return this .ptr .? [this .len ];
56
56
}
57
57
58
58
pub fn clone (this : @This (), allocator : std .mem .Allocator ) ! @This () {
@@ -66,7 +66,7 @@ pub fn BabyList(comptime Type: type) type {
66
66
}
67
67
68
68
pub fn appendAssumeCapacity (this : * @This (), value : Type ) void {
69
- this .ptr [this .len ] = value ;
69
+ this .ptr .? [this .len ] = value ;
70
70
this .len += 1 ;
71
71
std .debug .assert (this .cap >= this .len );
72
72
}
@@ -81,7 +81,7 @@ pub fn BabyList(comptime Type: type) type {
81
81
}
82
82
83
83
pub fn appendSliceAssumeCapacity (this : * @This (), values : []const Type ) void {
84
- var tail = this .ptr [this .len .. this .len + values .len ];
84
+ var tail = this .ptr .? [this .len .. this .len + values .len ];
85
85
std .debug .assert (this .cap >= this .len + @as (u32 , @truncate (values .len )));
86
86
bun .copy (Type , tail , values );
87
87
this .len += @as (u32 , @truncate (values .len ));
@@ -154,39 +154,39 @@ pub fn BabyList(comptime Type: type) type {
154
154
155
155
pub fn list (this : ListType ) std.ArrayListUnmanaged (Type ) {
156
156
return std .ArrayListUnmanaged (Type ){
157
- .items = this .ptr [0.. this .len ],
157
+ .items = this .ptr .? [0.. this .len ],
158
158
.capacity = this .cap ,
159
159
};
160
160
}
161
161
162
162
pub fn listManaged (this : ListType , allocator : std.mem.Allocator ) std.ArrayList (Type ) {
163
163
return std .ArrayList (Type ){
164
- .items = this .ptr [0.. this .len ],
164
+ .items = this .ptr .? [0.. this .len ],
165
165
.capacity = this .cap ,
166
166
.allocator = allocator ,
167
167
};
168
168
}
169
169
170
170
pub inline fn first (this : ListType ) ? * Type {
171
- return if (this .len > 0 ) this .ptr [0 ] else @as (? * Type , null );
171
+ return if (this .len > 0 ) this .ptr .? [0 ] else @as (? * Type , null );
172
172
}
173
173
174
174
pub inline fn last (this : ListType ) ? * Type {
175
- return if (this .len > 0 ) & this .ptr [this .len - 1 ] else @as (? * Type , null );
175
+ return if (this .len > 0 ) & this .ptr .? [this .len - 1 ] else @as (? * Type , null );
176
176
}
177
177
178
178
pub inline fn first_ (this : ListType ) Type {
179
- return this .ptr [0 ];
179
+ return this .ptr .? [0 ];
180
180
}
181
181
182
182
pub inline fn at (this : ListType , index : usize ) * const Type {
183
183
std .debug .assert (index < this .len );
184
- return & this .ptr [index ];
184
+ return & this .ptr .? [index ];
185
185
}
186
186
187
187
pub inline fn mut (this : ListType , index : usize ) * Type {
188
188
std .debug .assert (index < this .len );
189
- return & this .ptr [index ];
189
+ return & this .ptr .? [index ];
190
190
}
191
191
192
192
pub fn one (allocator : std.mem.Allocator , value : Type ) ! ListType {
@@ -200,7 +200,7 @@ pub fn BabyList(comptime Type: type) type {
200
200
}
201
201
202
202
pub inline fn @"[0]" (this : ListType ) Type {
203
- return this .ptr [0 ];
203
+ return this .ptr .? [0 ];
204
204
}
205
205
const OOM = error {OutOfMemory };
206
206
@@ -218,7 +218,7 @@ pub fn BabyList(comptime Type: type) type {
218
218
219
219
pub inline fn slice (this : ListType ) []Type {
220
220
@setRuntimeSafety (false );
221
- return this .ptr [0.. this .len ];
221
+ return this .ptr .? [0.. this .len ];
222
222
}
223
223
224
224
pub fn write (this : * @This (), allocator : std .mem .Allocator , str : []const u8 ) ! u32 {
0 commit comments