@@ -263,8 +263,8 @@ pub fn zeroes(comptime T: type) T {
263263 .pointer = > | ptr_info | {
264264 switch (ptr_info .size ) {
265265 .slice = > {
266- if (ptr_info .sentinel ) | sentinel | {
267- if (ptr_info .child == u8 and @as ( * const u8 , @ptrCast ( sentinel )) .* == 0 ) {
266+ if (ptr_info .sentinel () ) | sentinel | {
267+ if (ptr_info .child == u8 and sentinel == 0 ) {
268268 return "" ; // A special case for the most common use-case: null-terminated strings.
269269 }
270270 @compileError ("Can't set a sentinel slice to zero. This would require allocating memory." );
@@ -282,11 +282,7 @@ pub fn zeroes(comptime T: type) T {
282282 }
283283 },
284284 .array = > | info | {
285- if (info .sentinel ) | sentinel_ptr | {
286- const sentinel = @as (* align (1 ) const info .child , @ptrCast (sentinel_ptr )).* ;
287- return [_ :sentinel ]info.child {zeroes (info .child )} ** info .len ;
288- }
289- return [_ ]info.child {zeroes (info .child )} ** info .len ;
285+ return @splat (zeroes (info .child ));
290286 },
291287 .vector = > | info | {
292288 return @splat (zeroes (info .child ));
@@ -456,9 +452,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
456452 @field (value , field .name ) = @field (init , field .name );
457453 },
458454 }
459- } else if (field .default_value ) | default_value_ptr | {
460- const default_value = @as (* align (1 ) const field .type , @ptrCast (default_value_ptr )).* ;
461- @field (value , field .name ) = default_value ;
455+ } else if (field .defaultValue ()) | val | {
456+ @field (value , field .name ) = val ;
462457 } else {
463458 switch (@typeInfo (field .type )) {
464459 .@"struct" = > {
@@ -782,10 +777,10 @@ fn Span(comptime T: type) type {
782777 var new_ptr_info = ptr_info ;
783778 switch (ptr_info .size ) {
784779 .c = > {
785- new_ptr_info .sentinel = &@as (ptr_info .child , 0 );
780+ new_ptr_info .sentinel_ptr = &@as (ptr_info .child , 0 );
786781 new_ptr_info .is_allowzero = false ;
787782 },
788- .many = > if (ptr_info .sentinel == null ) @compileError ("invalid type given to std.mem.span: " ++ @typeName (T )),
783+ .many = > if (ptr_info .sentinel () == null ) @compileError ("invalid type given to std.mem.span: " ++ @typeName (T )),
789784 .one , .slice = > @compileError ("invalid type given to std.mem.span: " ++ @typeName (T )),
790785 }
791786 new_ptr_info .size = .slice ;
@@ -822,8 +817,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
822817 const Result = Span (@TypeOf (ptr ));
823818 const l = len (ptr );
824819 const ptr_info = @typeInfo (Result ).pointer ;
825- if (ptr_info .sentinel ) | s_ptr | {
826- const s = @as (* align (1 ) const ptr_info .child , @ptrCast (s_ptr )).* ;
820+ if (ptr_info .sentinel ()) | s | {
827821 return ptr [0.. l :s ];
828822 } else {
829823 return ptr [0.. l ];
@@ -853,12 +847,11 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
853847 // The return type must only be sentinel terminated if we are guaranteed
854848 // to find the value searched for, which is only the case if it matches
855849 // the sentinel of the type passed.
856- if (array_info .sentinel ) | sentinel_ptr | {
857- const sentinel = @as (* align (1 ) const array_info .child , @ptrCast (sentinel_ptr )).* ;
858- if (end == sentinel ) {
859- new_ptr_info .sentinel = & end ;
850+ if (array_info .sentinel ()) | s | {
851+ if (end == s ) {
852+ new_ptr_info .sentinel_ptr = & end ;
860853 } else {
861- new_ptr_info .sentinel = null ;
854+ new_ptr_info .sentinel_ptr = null ;
862855 }
863856 }
864857 },
@@ -868,17 +861,16 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
868861 // The return type must only be sentinel terminated if we are guaranteed
869862 // to find the value searched for, which is only the case if it matches
870863 // the sentinel of the type passed.
871- if (ptr_info .sentinel ) | sentinel_ptr | {
872- const sentinel = @as (* align (1 ) const ptr_info .child , @ptrCast (sentinel_ptr )).* ;
873- if (end == sentinel ) {
874- new_ptr_info .sentinel = & end ;
864+ if (ptr_info .sentinel ()) | s | {
865+ if (end == s ) {
866+ new_ptr_info .sentinel_ptr = & end ;
875867 } else {
876- new_ptr_info .sentinel = null ;
868+ new_ptr_info .sentinel_ptr = null ;
877869 }
878870 }
879871 },
880872 .c = > {
881- new_ptr_info .sentinel = & end ;
873+ new_ptr_info .sentinel_ptr = & end ;
882874 // C pointers are always allowzero, but we don't want the return type to be.
883875 assert (new_ptr_info .is_allowzero );
884876 new_ptr_info .is_allowzero = false ;
@@ -906,8 +898,7 @@ pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo(
906898 const Result = SliceTo (@TypeOf (ptr ), end );
907899 const length = lenSliceTo (ptr , end );
908900 const ptr_info = @typeInfo (Result ).pointer ;
909- if (ptr_info .sentinel ) | s_ptr | {
910- const s = @as (* align (1 ) const ptr_info .child , @ptrCast (s_ptr )).* ;
901+ if (ptr_info .sentinel ()) | s | {
911902 return ptr [0.. length :s ];
912903 } else {
913904 return ptr [0.. length ];
@@ -959,37 +950,34 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
959950 .pointer = > | ptr_info | switch (ptr_info .size ) {
960951 .one = > switch (@typeInfo (ptr_info .child )) {
961952 .array = > | array_info | {
962- if (array_info .sentinel ) | sentinel_ptr | {
963- const sentinel = @as (* align (1 ) const array_info .child , @ptrCast (sentinel_ptr )).* ;
964- if (sentinel == end ) {
953+ if (array_info .sentinel ()) | s | {
954+ if (s == end ) {
965955 return indexOfSentinel (array_info .child , end , ptr );
966956 }
967957 }
968958 return indexOfScalar (array_info .child , ptr , end ) orelse array_info .len ;
969959 },
970960 else = > {},
971961 },
972- .many = > if (ptr_info .sentinel ) | sentinel_ptr | {
973- const sentinel = @as (* align (1 ) const ptr_info .child , @ptrCast (sentinel_ptr )).* ;
974- if (sentinel == end ) {
962+ .many = > if (ptr_info .sentinel ()) | s | {
963+ if (s == end ) {
975964 return indexOfSentinel (ptr_info .child , end , ptr );
976965 }
977966 // We're looking for something other than the sentinel,
978967 // but iterating past the sentinel would be a bug so we need
979968 // to check for both.
980969 var i : usize = 0 ;
981- while (ptr [i ] != end and ptr [i ] != sentinel ) i += 1 ;
970+ while (ptr [i ] != end and ptr [i ] != s ) i += 1 ;
982971 return i ;
983972 },
984973 .c = > {
985974 assert (ptr != null );
986975 return indexOfSentinel (ptr_info .child , end , ptr );
987976 },
988977 .slice = > {
989- if (ptr_info .sentinel ) | sentinel_ptr | {
990- const sentinel = @as (* align (1 ) const ptr_info .child , @ptrCast (sentinel_ptr )).* ;
991- if (sentinel == end ) {
992- return indexOfSentinel (ptr_info .child , sentinel , ptr );
978+ if (ptr_info .sentinel ()) | s | {
979+ if (s == end ) {
980+ return indexOfSentinel (ptr_info .child , s , ptr );
993981 }
994982 }
995983 return indexOfScalar (ptr_info .child , ptr , end ) orelse ptr .len ;
@@ -1040,9 +1028,8 @@ pub fn len(value: anytype) usize {
10401028 switch (@typeInfo (@TypeOf (value ))) {
10411029 .pointer = > | info | switch (info .size ) {
10421030 .many = > {
1043- const sentinel_ptr = info .sentinel orelse
1031+ const sentinel = info .sentinel () orelse
10441032 @compileError ("invalid type given to std.mem.len: " ++ @typeName (@TypeOf (value )));
1045- const sentinel = @as (* align (1 ) const info .child , @ptrCast (sentinel_ptr )).* ;
10461033 return indexOfSentinel (info .child , sentinel , value );
10471034 },
10481035 .c = > {
@@ -3587,7 +3574,7 @@ fn ReverseIterator(comptime T: type) type {
35873574 var new_ptr_info = ptr_info ;
35883575 new_ptr_info .size = .many ;
35893576 new_ptr_info .child = array_info .child ;
3590- new_ptr_info .sentinel = array_info .sentinel ;
3577+ new_ptr_info .sentinel_ptr = array_info .sentinel_ptr ;
35913578 break :blk @Type (.{ .pointer = new_ptr_info });
35923579 },
35933580 else = > {},
@@ -3608,7 +3595,7 @@ fn ReverseIterator(comptime T: type) type {
36083595 var ptr = @typeInfo (Pointer ).pointer ;
36093596 ptr .size = .one ;
36103597 ptr .child = Element ;
3611- ptr .sentinel = null ;
3598+ ptr .sentinel_ptr = null ;
36123599 break :ptr ptr ;
36133600 } });
36143601 return struct {
@@ -3979,7 +3966,7 @@ fn CopyPtrAttrs(
39793966 .alignment = info .alignment ,
39803967 .address_space = info .address_space ,
39813968 .child = child ,
3982- .sentinel = null ,
3969+ .sentinel_ptr = null ,
39833970 },
39843971 });
39853972}
@@ -4547,7 +4534,7 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) t
45474534 .alignment = new_alignment ,
45484535 .address_space = info .address_space ,
45494536 .child = info .child ,
4550- .sentinel = null ,
4537+ .sentinel_ptr = null ,
45514538 },
45524539 });
45534540}
0 commit comments