authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-02-21 19:46:53+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-02-21 19:46:53+01:00
log783e8ad0319b950a1d42d5a93e4fbb9e9df1be10
tree81b12200e10eb03167c48a7115edca5d6dbac4e4
parentfdae5f5a07c043d9eeefe4933bcfbd03df581fde

remove @bytesToSlice, @sliceToBytes from std lib


11 files changed, 28 insertions(+), 28 deletions(-)

lib/std/crypto/gimli.zig+2-2
......@@ -24,11 +24,11 @@ pub const State = struct {
2424 const Self = @This();
2525
2626 pub fn toSlice(self: *Self) []u8 {
27 return @sliceToBytes(self.data[0..]);
27 return mem.sliceAsBytes(self.data[0..]);
2828 }
2929
3030 pub fn toSliceConst(self: *Self) []const u8 {
31 return @sliceToBytes(self.data[0..]);
31 return mem.sliceAsBytes(self.data[0..]);
3232 }
3333
3434 pub fn permute(self: *Self) void {
lib/std/cstr.zig+1-1
......@@ -72,7 +72,7 @@ pub const NullTerminated2DArray = struct {
7272 errdefer allocator.free(buf);
7373
7474 var write_index = index_size;
75 const index_buf = @bytesToSlice(?[*]u8, buf);
75 const index_buf = mem.bytesAsSlice(?[*]u8, buf);
7676
7777 var i: usize = 0;
7878 for (slices) |slice| {
lib/std/fifo.zig+4-4
......@@ -101,7 +101,7 @@ pub fn LinearFifo(
101101 }
102102 }
103103 { // set unused area to undefined
104 const unused = @sliceToBytes(self.buf[self.count..]);
104 const unused = mem.sliceAsBytes(self.buf[self.count..]);
105105 @memset(unused.ptr, undefined, unused.len);
106106 }
107107 }
......@@ -166,12 +166,12 @@ pub fn LinearFifo(
166166 { // set old range to undefined. Note: may be wrapped around
167167 const slice = self.readableSliceMut(0);
168168 if (slice.len >= count) {
169 const unused = @sliceToBytes(slice[0..count]);
169 const unused = mem.sliceAsBytes(slice[0..count]);
170170 @memset(unused.ptr, undefined, unused.len);
171171 } else {
172 const unused = @sliceToBytes(slice[0..]);
172 const unused = mem.sliceAsBytes(slice[0..]);
173173 @memset(unused.ptr, undefined, unused.len);
174 const unused2 = @sliceToBytes(self.readableSliceMut(slice.len)[0 .. count - slice.len]);
174 const unused2 = mem.sliceAsBytes(self.readableSliceMut(slice.len)[0 .. count - slice.len]);
175175 @memset(unused2.ptr, undefined, unused2.len);
176176 }
177177 }
lib/std/fs/watch.zig+1-1
......@@ -26,7 +26,7 @@ fn eqlString(a: []const u16, b: []const u16) bool {
2626}
2727
2828fn hashString(s: []const u16) u32 {
29 return @truncate(u32, std.hash.Wyhash.hash(0, @sliceToBytes(s)));
29 return @truncate(u32, std.hash.Wyhash.hash(0, mem.sliceAsBytes(s)));
3030}
3131
3232const WatchEventError = error{
lib/std/heap.zig+3-3
......@@ -283,14 +283,14 @@ const WasmPageAllocator = struct {
283283
284284 fn getBit(self: FreeBlock, idx: usize) PageStatus {
285285 const bit_offset = 0;
286 return @intToEnum(PageStatus, Io.get(@sliceToBytes(self.data), idx, bit_offset));
286 return @intToEnum(PageStatus, Io.get(mem.sliceAsBytes(self.data), idx, bit_offset));
287287 }
288288
289289 fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {
290290 const bit_offset = 0;
291291 var i: usize = 0;
292292 while (i < len) : (i += 1) {
293 Io.set(@sliceToBytes(self.data), start_idx + i, bit_offset, @enumToInt(val));
293 Io.set(mem.sliceAsBytes(self.data), start_idx + i, bit_offset, @enumToInt(val));
294294 }
295295 }
296296
......@@ -552,7 +552,7 @@ pub const ArenaAllocator = struct {
552552 if (len >= actual_min_size) break;
553553 }
554554 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);
555 const buf_node_slice = @bytesToSlice(BufNode, buf[0..@sizeOf(BufNode)]);
555 const buf_node_slice = mem.bytesAsSlice(BufNode, buf[0..@sizeOf(BufNode)]);
556556 const buf_node = &buf_node_slice[0];
557557 buf_node.* = BufNode{
558558 .data = buf,
lib/std/io/in_stream.zig+1-1
......@@ -235,7 +235,7 @@ pub fn InStream(comptime ReadError: type) type {
235235 // Only extern and packed structs have defined in-memory layout.
236236 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
237237 var res: [1]T = undefined;
238 try self.readNoEof(@sliceToBytes(res[0..]));
238 try self.readNoEof(mem.sliceAsBytes(res[0..]));
239239 return res[0];
240240 }
241241
lib/std/mem.zig+6-6
......@@ -132,7 +132,7 @@ pub const Allocator = struct {
132132 // their own frame with @Frame(func).
133133 return @intToPtr([*]T, @ptrToInt(byte_slice.ptr))[0..n];
134134 } else {
135 return @bytesToSlice(T, @alignCast(a, byte_slice));
135 return mem.bytesAsSlice(T, @alignCast(a, byte_slice));
136136 }
137137 }
138138
......@@ -173,7 +173,7 @@ pub const Allocator = struct {
173173 return @as([*]align(new_alignment) T, undefined)[0..0];
174174 }
175175
176 const old_byte_slice = @sliceToBytes(old_mem);
176 const old_byte_slice = mem.sliceAsBytes(old_mem);
177177 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory;
178178 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
179179 const byte_slice = try self.reallocFn(self, old_byte_slice, Slice.alignment, byte_count, new_alignment);
......@@ -181,7 +181,7 @@ pub const Allocator = struct {
181181 if (new_n > old_mem.len) {
182182 @memset(byte_slice.ptr + old_byte_slice.len, undefined, byte_slice.len - old_byte_slice.len);
183183 }
184 return @bytesToSlice(T, @alignCast(new_alignment, byte_slice));
184 return mem.bytesAsSlice(T, @alignCast(new_alignment, byte_slice));
185185 }
186186
187187 /// Prefer calling realloc to shrink if you can tolerate failure, such as
......@@ -221,18 +221,18 @@ pub const Allocator = struct {
221221 // new_n <= old_mem.len and the multiplication didn't overflow for that operation.
222222 const byte_count = @sizeOf(T) * new_n;
223223
224 const old_byte_slice = @sliceToBytes(old_mem);
224 const old_byte_slice = mem.sliceAsBytes(old_mem);
225225 @memset(old_byte_slice.ptr + byte_count, undefined, old_byte_slice.len - byte_count);
226226 const byte_slice = self.shrinkFn(self, old_byte_slice, Slice.alignment, byte_count, new_alignment);
227227 assert(byte_slice.len == byte_count);
228 return @bytesToSlice(T, @alignCast(new_alignment, byte_slice));
228 return mem.bytesAsSlice(T, @alignCast(new_alignment, byte_slice));
229229 }
230230
231231 /// Free an array allocated with `alloc`. To free a single item,
232232 /// see `destroy`.
233233 pub fn free(self: *Allocator, memory: var) void {
234234 const Slice = @typeInfo(@TypeOf(memory)).Pointer;
235 const bytes = @sliceToBytes(memory);
235 const bytes = mem.sliceAsBytes(memory);
236236 const bytes_len = bytes.len + if (Slice.sentinel != null) @sizeOf(Slice.child) else 0;
237237 if (bytes_len == 0) return;
238238 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));
lib/std/net.zig+2-2
......@@ -120,7 +120,7 @@ pub const Address = extern union {
120120 ip_slice[10] = 0xff;
121121 ip_slice[11] = 0xff;
122122
123 const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]);
123 const ptr = mem.sliceAsBytes(@as(*const [1]u32, &addr)[0..]);
124124
125125 ip_slice[12] = ptr[0];
126126 ip_slice[13] = ptr[1];
......@@ -164,7 +164,7 @@ pub const Address = extern union {
164164 .addr = undefined,
165165 },
166166 };
167 const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]);
167 const out_ptr = mem.sliceAsBytes(@as(*[1]u32, &result.in.addr)[0..]);
168168
169169 var x: u8 = 0;
170170 var index: u8 = 0;
lib/std/os.zig+1-1
......@@ -1778,7 +1778,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
17781778
17791779 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
17801780 const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];
1781 const name_wide = @bytesToSlice(u16, name_bytes);
1781 const name_wide = mem.bytesAsSlice(u16, name_bytes);
17821782 return mem.indexOf(u16, name_wide, &[_]u16{ 'm', 's', 'y', 's', '-' }) != null or
17831783 mem.indexOf(u16, name_wide, &[_]u16{ '-', 'p', 't', 'y' }) != null;
17841784}
lib/std/process.zig+1-1
......@@ -436,7 +436,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
436436 const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes);
437437 errdefer allocator.free(buf);
438438
439 const result_slice_list = @bytesToSlice([]u8, buf[0..slice_list_bytes]);
439 const result_slice_list = mem.bytesAsSlice([]u8, buf[0..slice_list_bytes]);
440440 const result_contents = buf[slice_list_bytes..];
441441 mem.copy(u8, result_contents, contents_slice);
442442
lib/std/unicode.zig+6-6
......@@ -243,7 +243,7 @@ pub const Utf16LeIterator = struct {
243243
244244 pub fn init(s: []const u16) Utf16LeIterator {
245245 return Utf16LeIterator{
246 .bytes = @sliceToBytes(s),
246 .bytes = mem.sliceAsBytes(s),
247247 .i = 0,
248248 };
249249 }
......@@ -496,7 +496,7 @@ pub fn utf16leToUtf8(utf8: []u8, utf16le: []const u16) !usize {
496496
497497test "utf16leToUtf8" {
498498 var utf16le: [2]u16 = undefined;
499 const utf16le_as_bytes = @sliceToBytes(utf16le[0..]);
499 const utf16le_as_bytes = mem.sliceAsBytes(utf16le[0..]);
500500
501501 {
502502 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
......@@ -606,12 +606,12 @@ test "utf8ToUtf16Le" {
606606 {
607607 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
608608 testing.expectEqual(@as(usize, 2), length);
609 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", @sliceToBytes(utf16le[0..]));
609 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
610610 }
611611 {
612612 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
613613 testing.expectEqual(@as(usize, 2), length);
614 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", @sliceToBytes(utf16le[0..]));
614 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
615615 }
616616}
617617
......@@ -619,13 +619,13 @@ test "utf8ToUtf16LeWithNull" {
619619 {
620620 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
621621 defer testing.allocator.free(utf16);
622 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", @sliceToBytes(utf16[0..]));
622 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
623623 testing.expect(utf16[2] == 0);
624624 }
625625 {
626626 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
627627 defer testing.allocator.free(utf16);
628 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", @sliceToBytes(utf16[0..]));
628 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
629629 testing.expect(utf16[2] == 0);
630630 }
631631}