Skip to content

Commit 4505857

Browse files
committed
revert changes outside std.fmt
1 parent 0b0de22 commit 4505857

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

lib/std/cstr.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test "cstr fns" {
2828

2929
fn testCStrFnsImpl() void {
3030
testing.expect(cmp("aoeu", "aoez") == -1);
31-
testing.expect(mem.len(u8, "123456789".*) == 9);
31+
testing.expect(mem.len(u8, "123456789") == 9);
3232
}
3333

3434
/// Returns a mutable, null-terminated slice with the same length as `slice`.

lib/std/mem.zig

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,31 +470,18 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
470470
return true;
471471
}
472472

473-
pub fn len(comptime T: type, ptr: var) usize {
474-
const sentinel: T = comptime meta.Sentinel(@TypeOf(ptr));
473+
pub fn len(comptime T: type, ptr: [*:0]const T) usize {
475474
var count: usize = 0;
476-
while (ptr[count] != sentinel) : (count += 1) {}
475+
while (ptr[count] != 0) : (count += 1) {}
477476
return count;
478477
}
479478

480-
/// Given a sentintel-terminated pointer-to-many, find the sentintel and return a slice.
481-
pub fn pointerToSlice(comptime T: type, ptr: blk: {
482-
var info = @typeInfo(T).Pointer;
483-
info.size = .Many;
484-
break :blk @Type(std.builtin.TypeInfo{ .Pointer = info });
485-
}) T {
486-
const sentinel = comptime meta.Sentinel(T);
487-
return ptr[0..len(meta.Child(T), ptr) :sentinel];
488-
}
489-
490-
/// Deprecated; use pointerToSlice instead
491479
pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
492-
return pointerToSlice([:0]const T, ptr);
480+
return ptr[0..len(T, ptr) :0];
493481
}
494482

495-
/// Deprecated; use pointerToSlice instead
496483
pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
497-
return pointerToSlice([:0]T, ptr);
484+
return ptr[0..len(T, ptr) :0];
498485
}
499486

500487
/// Returns true if all elements in a slice are equal to the scalar value provided

test/stage1/behavior/misc.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ test "string concatenation" {
335335
comptime expect(@TypeOf(a) == *const [12:0]u8);
336336
comptime expect(@TypeOf(b) == *const [12:0]u8);
337337

338-
const len = b.len;
338+
const len = mem.len(u8, b);
339339
const len_with_null = len + 1;
340340
{
341341
var i: u32 = 0;

0 commit comments

Comments
 (0)