Commit 4505857e30

Andrew Kelley <andrew@ziglang.org>
2020-03-01 19:07:31
revert changes outside std.fmt
1 parent 0b0de22
Changed files (3)
lib
test
stage1
behavior
lib/std/cstr.zig
@@ -28,7 +28,7 @@ test "cstr fns" {
 
 fn testCStrFnsImpl() void {
     testing.expect(cmp("aoeu", "aoez") == -1);
-    testing.expect(mem.len(u8, "123456789".*) == 9);
+    testing.expect(mem.len(u8, "123456789") == 9);
 }
 
 /// Returns a mutable, null-terminated slice with the same length as `slice`.
lib/std/mem.zig
@@ -470,31 +470,18 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
     return true;
 }
 
-pub fn len(comptime T: type, ptr: var) usize {
-    const sentinel: T = comptime meta.Sentinel(@TypeOf(ptr));
+pub fn len(comptime T: type, ptr: [*:0]const T) usize {
     var count: usize = 0;
-    while (ptr[count] != sentinel) : (count += 1) {}
+    while (ptr[count] != 0) : (count += 1) {}
     return count;
 }
 
-/// Given a sentintel-terminated pointer-to-many, find the sentintel and return a slice.
-pub fn pointerToSlice(comptime T: type, ptr: blk: {
-    var info = @typeInfo(T).Pointer;
-    info.size = .Many;
-    break :blk @Type(std.builtin.TypeInfo{ .Pointer = info });
-}) T {
-    const sentinel = comptime meta.Sentinel(T);
-    return ptr[0..len(meta.Child(T), ptr) :sentinel];
-}
-
-/// Deprecated; use pointerToSlice instead
 pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
-    return pointerToSlice([:0]const T, ptr);
+    return ptr[0..len(T, ptr) :0];
 }
 
-/// Deprecated; use pointerToSlice instead
 pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
-    return pointerToSlice([:0]T, ptr);
+    return ptr[0..len(T, ptr) :0];
 }
 
 /// Returns true if all elements in a slice are equal to the scalar value provided
test/stage1/behavior/misc.zig
@@ -335,7 +335,7 @@ test "string concatenation" {
     comptime expect(@TypeOf(a) == *const [12:0]u8);
     comptime expect(@TypeOf(b) == *const [12:0]u8);
 
-    const len = b.len;
+    const len = mem.len(u8, b);
     const len_with_null = len + 1;
     {
         var i: u32 = 0;