diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-01-25 10:03:26 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-25 10:03:26 -0500 |
| commit | f7670882aff5fb3a943057edd9da34d053b5fe59 (patch) | |
| tree | 7fa2c7f06331feaad43ba63b0969add120633d49 /std/array_list.zig | |
| parent | e5bc5873d74713bedbc32817ed31370c3256418d (diff) | |
| parent | 3671582c15235e5f79a84936ea2f834f6968ff8c (diff) | |
| download | zig-f7670882aff5fb3a943057edd9da34d053b5fe59.tar.gz zig-f7670882aff5fb3a943057edd9da34d053b5fe59.zip | |
Merge pull request #720 from zig-lang/require-return-type
syntax: functions require return type. remove `->`
Diffstat (limited to 'std/array_list.zig')
| -rw-r--r-- | std/array_list.zig | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/std/array_list.zig b/std/array_list.zig index a16dec113c..bc4d3c1d81 100644 --- a/std/array_list.zig +++ b/std/array_list.zig @@ -4,11 +4,11 @@ const assert = debug.assert; const mem = std.mem; const Allocator = mem.Allocator; -pub fn ArrayList(comptime T: type) -> type { +pub fn ArrayList(comptime T: type) type { return AlignedArrayList(T, @alignOf(T)); } -pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ +pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ return struct { const Self = this; @@ -20,7 +20,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ allocator: &Allocator, /// Deinitialize with `deinit` or use `toOwnedSlice`. - pub fn init(allocator: &Allocator) -> Self { + pub fn init(allocator: &Allocator) Self { return Self { .items = []align(A) T{}, .len = 0, @@ -28,22 +28,22 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ }; } - pub fn deinit(l: &Self) { + pub fn deinit(l: &Self) void { l.allocator.free(l.items); } - pub fn toSlice(l: &Self) -> []align(A) T { + pub fn toSlice(l: &Self) []align(A) T { return l.items[0..l.len]; } - pub fn toSliceConst(l: &const Self) -> []align(A) const T { + pub fn toSliceConst(l: &const Self) []align(A) const T { return l.items[0..l.len]; } /// ArrayList takes ownership of the passed in slice. The slice must have been /// allocated with `allocator`. /// Deinitialize with `deinit` or use `toOwnedSlice`. - pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) -> Self { + pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self { return Self { .items = slice, .len = slice.len, @@ -52,35 +52,35 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ } /// The caller owns the returned memory. ArrayList becomes empty. - pub fn toOwnedSlice(self: &Self) -> []align(A) T { + pub fn toOwnedSlice(self: &Self) []align(A) T { const allocator = self.allocator; const result = allocator.alignedShrink(T, A, self.items, self.len); *self = init(allocator); return result; } - pub fn append(l: &Self, item: &const T) -> %void { + pub fn append(l: &Self, item: &const T) %void { const new_item_ptr = try l.addOne(); *new_item_ptr = *item; } - pub fn appendSlice(l: &Self, items: []align(A) const T) -> %void { + pub fn appendSlice(l: &Self, items: []align(A) const T) %void { try l.ensureCapacity(l.len + items.len); mem.copy(T, l.items[l.len..], items); l.len += items.len; } - pub fn resize(l: &Self, new_len: usize) -> %void { + pub fn resize(l: &Self, new_len: usize) %void { try l.ensureCapacity(new_len); l.len = new_len; } - pub fn shrink(l: &Self, new_len: usize) { + pub fn shrink(l: &Self, new_len: usize) void { assert(new_len <= l.len); l.len = new_len; } - pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void { + pub fn ensureCapacity(l: &Self, new_capacity: usize) %void { var better_capacity = l.items.len; if (better_capacity >= new_capacity) return; while (true) { @@ -90,7 +90,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity); } - pub fn addOne(l: &Self) -> %&T { + pub fn addOne(l: &Self) %&T { const new_length = l.len + 1; try l.ensureCapacity(new_length); const result = &l.items[l.len]; @@ -98,12 +98,12 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ return result; } - pub fn pop(self: &Self) -> T { + pub fn pop(self: &Self) T { self.len -= 1; return self.items[self.len]; } - pub fn popOrNull(self: &Self) -> ?T { + pub fn popOrNull(self: &Self) ?T { if (self.len == 0) return null; return self.pop(); |
